vue展开收起文字

435 阅读1分钟
这是平时在实际开发中所总结出来的,不管难易,只希望和各位交流一下技术,分享一些东西,
共同进步,有什么更好的优化或者有问题欢迎评论区留言,大家帮帮点点赞哦~
<div v-for="item in list" :key="item.id">
    <span>
        {{ item.isExpand ? item.description : allExpand(item.description) }}
    </span>
    <span
      v-show="item.description && item.description.length > 58"
      style="color: #007aff"
      @click.stop="clickExpand(item.id)"
    >
        {{ item.isExpand ? '收起' : '查看详情>>' }}
    </span>
</div>

// 点击列表页展开和收起按钮
clickExpand (index) {
   this.list.forEach(c => {
      if (index === c._id) {
        c.isExpand = !c.isExpand
      }
   })
},
// 列表详情展开的内容的展示
allExpand (value) {
    if (!value) return
    value = value.toString()
    if (value.length > 450) {
        return value.substr(0, 450) + '...'
    } else {
        return false
    }
},