window.onresize直接可以监听到窗口变化,并执行事件。
注意:第一次进入页面的时候window.onresize不会执行,而第一次进入的时候需要赋值.
实例:
created () {
this.clientHeight = document.documentElement.clientHeight
},
mounted() {
const that = this;
window.onresize=function () {
that.clientHeight = document.documentElement.clientHeight
};
},