element-resize-detector 元素监听
https://github.com/wnr/element-resize-detector
npm install element-resize-detector
import elementResizeDetectorMaker from "element-resize-detector"
// 或者
let elementResizeDetectorMaker = require("element-resize-detector");
<div ref="adaptionBox" id="adaptionBox" style="width:200px;height:200px;background:green"></div>
<div ref="tableBox" id="tableBox" style="width:200px;height:200px;background:red"></div>
data() {
return {
erd: null
}
},
mounted(){
this.erd = elementResizeDetectorMaker();
this.$nextTick(() => {
this.erd.listenTo(this.$refs.adaptionBox, element => {
this.$refs.tableBox.style.height = window.innerHeight - element.offsetHeight;
});
})
}
或者
mounted(){
this.erd = elementResizeDetectorMaker();
this.$nextTick(() => {
this.erd.listenTo(document.getElementById("adaptionBox"), element => {
document.getElementById("tableBox").style.height = window.innerHeight - element.offsetHeight;
});
})
}