vue 实现多行文本 超出行数后 省略号,出现查看全文按钮,点击 展示全文
HTML<el-cardclass="box-card" shadow="hover" v-for="(moodEssayDate,index) in moodEssayDates" :key="moodEssayDate.pk_moodEssay"><div class="card"><div class="cardL...
·
- HTML
<el-card class="box-card" shadow="hover" v-for="(moodEssayDate,index) in moodEssayDates" :key="moodEssayDate.pk_moodEssay">
<div class="card">
<div class="cardLeft">
<el-avatar src=" https://img.jbzj.com/file_images/article/201310/20131008165929119.jpg"></el-avatar>
<swingingPendant class="swingingPendant" v-show="!isLogin"></swingingPendant>
</div>
<div class="cardCenter">
<div class="cardCenterHeader">
<div class="articleTitle"><label>{{moodEssayDate.essayTitle}}</label></div>
<span><i class="el-icon-time"></i>{{moodEssayDate.ts}}</span>
</div>
<div class="cardCenterBody">
<div class="cardCenterBodyTop">
<div :class="[moodEssayDate.isAll?'articleContent':'articleContent2']" ref="articleContent">{{moodEssayDate.essayContent}}</div>
<el-button class="checkArticle" type="text" @click="showAllContent(moodEssayDate,index)" v-show="moodEssayDate.showAllContentBtn">展开查看全文</el-button>
<el-button style="margin: 0;" type="text" @click="NotShowAllContent(moodEssayDate,index)" v-show="moodEssayDate.packUpArticle" icon="el-icon-top">收起</el-button>
</div>
<div class="articleBtnS">
<div v-show="!isLogin">——无心语录</div>
<el-button :loading="DelBtnLoading" v-show="isLogin" @click="DelMoodEssay(moodEssayDate)" type="primary" icon="el-icon-delete ">删除</el-button>
</div>
</div>
</div>
</div>
</el-card>
- JS部分
//随笔初始化
getAllMessages(){
getAllMessages().then(res=>{
for(let i=0;i<res.data.moodEssayList.length;i++){
this.$set(res.data.moodEssayList[i], 'index', i)
this.$set(res.data.moodEssayList[i], 'packUpArticle', false)
this.$set(res.data.moodEssayList[i], 'showAllContentBtn', false)
this.$set(res.data.moodEssayList[i], 'isAll', true)
}
this.currentTotal = res.data.moodEssayList.length
this.moodEssayDates = res.data.moodEssayList.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
setTimeout(() => {
if(this.$refs.articleContent){
for(let i = 0;i<this.$refs.articleContent.length;i++){
if(this.$refs.articleContent[i].offsetHeight>=189){
this.$set(this.moodEssayDates[i], 'showAllContentBtn', true)
}
}
}
}, 200);
})
},
//展开全文
showAllContent(moodEssayDate,index){
this.$set(this.moodEssayDates[index], 'isAll', false)
this.$set(this.moodEssayDates[index], 'showAllContentBtn', false)
this.$set(this.moodEssayDates[index], 'packUpArticle', true)
},
// 收起
NotShowAllContent(moodEssayDate,index){
this.$set(this.moodEssayDates[index], 'isAll', true)
this.$set(this.moodEssayDates[index], 'showAllContentBtn', true)
this.$set(this.moodEssayDates[index], 'packUpArticle', false)
},
- 效果图
更多推荐
已为社区贡献7条内容
所有评论(0)