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