超过两行...,只有两行或少于两行无...且没有查看更多文字 关键思路:超过两行...用ellipsis,但是为了判断文字是否多余两行,所以要获取节点的高度,如果大于两行则文字出现,否则没有更多文字

关键代码:

This.dataList = this.dataList.map((item,index)=>{

Let showFlag = this.$refs.textContent[index].offsetHeight > 44 ? true : false

If(this.$refs.textContent[index].offsetHeight > 44){

This.$refs.textContent[index].style.overflow = ‘hidden’

This.$refs.textContent[index].style.textOverflow = ‘ellipsis’

This.$refs.textContent[index].style.display = ‘-webkit-box’

}

})

//因为原生的style中没有属性-webkit-line-clamp: 2; -webkit-box-orient: vertical;

所以直接写在css中,最后要切样式 overflow: auto; text-overflow: clip; display: block;-webkit-line-clamp: none; -webkit-box-orient: inherit; line-height: 22px;

原文地址:https://www.cnblogs.com/wangge001/p/10131097.html