vue中使两个不同高度的div(内容长度不一)高度相同 多次总结优化后不会报错的
//定义一个newData(变化的),设置divHeight高
<div class="grid-content bg-purple" :style="{ height: divHeight }">
xxxxxx
</div>
<div class="series-basic" ref="newData"></div>
//监听:queryDetaildata是接口获取到的数据
watch: {
queryDetaildata: {
handler() {
this.$nextTick(() => {
//解决TypeError: Cannot read properties of undefined (reading '$el') at eval报错
if (this.$refs.newData && this.$refs.newData.clientHeight) {
this.divHeight = `${this.$refs.newData.clientHeight}px`;
}
//浏览器自适应
window.addEventListener('resize', () => {
//解决TypeError: Cannot read properties of undefined (reading '$el') at eval报错
if (this.$refs.newData && this.$refs.newData.clientHeight) {
this.divHeight = `${this.$refs.newData.clientHeight}px`;
}
});
});
},
immediate: true
}
},
参考连接:https://blog.csdn.net/sunwenpinglike/article/details/129690571

浙公网安备 33010602011771号