比上監(jiān)聽省事多了,敲爽
直接上代碼
test.vue
data () {
return {
windowWidth: document.documentElement.clientWidth, //實時屏幕寬度
windowHeight: document.documentElement.clientHeight, //實時屏幕高度
}
},
mounted() {
// 實時獲取瀏覽器寬度高度
let that = this;
window.onresize = () => {
return (() => {
window.fullHeight = document.documentElement.clientHeight;
window.fullWidth = document.documentElement.clientWidth;
that.windowHeight = window.fullHeight; // 高
that.windowWidth = window.fullWidth; // 寬
})()
};
}