vue中在mounted中window.onresize不生效是因为:
引用的父组件和子组件都使用了window.onresize以至于一个window.onresize失效。
把window.onresize改为window.addEventListener
window.onresize = () => {
if (screenfull.isFullscreen) {
this.show = false;
this.tableHeight = window.innerHeight * 0.9;
} else {
this.show = true;
this.tableHeight = window.innerHeight * 0.8;
}
};
改成
window.addEventListener('resize', () => {
if (screenfull.isFullscreen) {
this.show = false;
this.tableHeight = window.innerHeight * 0.95;
} else {
this.show = true;
this.tableHeight = window.innerHeight * 0.8;
}
});