廢話不多說(shuō)直接上代碼
<div ref="detailDom">
this.$nextTick(() => {
? ? ? this.detailDom = this.$refs.detailDom
? ? ? this.showDetailBtn = this.detailDom.clientHeight < this.detailDom.scrollHeight
? ? ? console.log(this.detailDom.clientHeight)
? ? ? console.log(this.detailDom.scrollHeight)
? ? const text = this.deteil//文本
? ? ? const el = this.$refs.detailDom
? ? ? const h = el.offsetHeight
? ? ? console.log(h)
? ? ? console.log(el.scrollHeight)
? ? ? for(let i = 0; i <= text.length; i++) {
? ? ? ? ? el.innerHTML = text.substr(0, i);
? ? ? ? ? if(h < el.scrollHeight) {
? ? ? ? ? ? ? el.style.overflow = 'hidden';
? ? ? ? ? ? ? el.innerHTML = text.substr(0, i-3) + '...'
? ? ? ? ? ? ? break;
? ? ? ? ? }
? ? ? }
? ? })