1、设置变量:

data() {
    return {
        clientHeight: document.documentElement.clientHeight
    }
}

2、页面初始化时给onresize函数赋值:

mounted() {
    window.onresize = () => {
        this.clientHeight = document.documentElement.clientHeight;
    }
}

3、使用watch监听变量值得变化:

watch: {
    clientHeight(newValue, oldValue) {
        if(newValue) {
            console.log(this.clientHeight);
        }
    }
}

 

Logo

前往低代码交流专区

更多推荐