<view v-if="video.comment.length>20" @click="lookAll(video)">
<view v-if="copenList.findIndex(it=>it.id==video.id)==-1" class="u-flex">
<view class="comment_not_all">评论:{{video.comment}}</view>
<view style="color: #0084bf;">
展开
</view>
</view>
<view v-else>
<view v-for="(flag,iii) in copenList" :key="iii" v-if="flag.id==video.id"
:class="flag.open==0?'u-flex':''">
<view :class="flag.open==0?'comment_not_all':'comment_all'">评论:{{video.comment}}
</view>
<view class="u-flex u-row-right" style="color: #0084bf;">
{{flag.open==0?'展开':'收起'}}
</view>
</view>
</view>
</view>
<view v-else>
<view class="comment">评论:{{video.comment}}</view>
</view>
.comment {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
// white-space: w;
}
.comment_not_all {
width: 600rpx;
overflow: hidden;
text-overflow: ellipsis;
}
.comment_all {
white-space: normal;
word-break: break-all;
word-wrap: break-word;
}
lookAll(item) {
let index = this.copenList.findIndex(it => it.id == item.id)
if (index == -1) {
let id = item.id
let obj = {
id: item.id,
open: 1
}
this.copenList.push(obj)
} else {
let value = this.copenList[index].open
let nvalue = value == 0 ? 1 : 0
this.copenList[index].open = nvalue
}
}
外层v-if(v-if="video.comment.length>20"):
判断文本内容长短有没有超过20,如果为false直接显示全部内容
第二个v-if (v-if="copenList.findIndex(it=>it.id==video.id)==-1") 判断copenList(用于存储点击过的文本)是否有该条数据,若没有点击过则显示部分内容(样式comment_not_all)、文字“展开”;若点击过则遍历copenList列表查询对应数据;
函数lookAll 点击文本内容时调用,判断是否已存在,不存在则将该条数据添加到copenList,存在则更改当前的状态:0--收起,1--展开,