data () {
return {
screenWidth: document.body.clientWidth, //屏幕可视区宽度
screenHeight: document.body.clientHeight //屏幕高度
}
},
mounted () {
// 监听窗口变化
let _this = this
window.addEventListener('resize',function () {
_this.screenWidth = document.body.clientWidth;
_this.screenHeight = document.body.clientHeight;
})
},
watch: {
// 窗口宽度改变
screenWidth(n,o){
},
// 窗口高度改变
screenHeight(n,o){
}
},
vue监听窗口变化
最新推荐文章于 2024-03-26 18:57:06 发布