当前元素宽度无法得知,可求父元素和兄弟元素
html
<div id="div-comlist-name" ref="div_comlist_name" >
<div style="width:90px">兄弟元素</div>
<div :style="{ 'max-width':complist_name_width}" >当前元素</div>
</div>
js
data() {
return {
complist_name_width: '190px',
}
methods: {
getWidthDivComlistName() {
// console.log(this.$refs.div_comlist_name);
let divWidth = this.$refs.div_comlist_name[0]
// console.log(divWidth.clientWidth);
if (divWidth.clientWidth && divWidth.clientWidth > 0) {
this.complist_name_width = (divWidth.clientWidth - 90) + 'px'
} else {
this.complist_name_width = '190px'
}
},
}
}