有时候我们需要vue 判断元素内容是否超过宽度,废话不多说直接上代码
let isOverflow = this.$refs.isOverflow;
for (let i in isOverflow) {
let cWidth = isOverflow[i].clientWidth;
let sWidth = isOverflow[i].scrollWidth;
if (sWidth > cWidth) { //超过
this.$set(this.isEllipsis, i, true);
} else {
this.$set(this.isEllipsis, i, false);
}
}
以上就是关键代码可以根据自己需要进行修改