data(){
return {
screenWidth: document.body.clientWidth
}
},
mounted() {
//监听浏览器大小
let that = this;
window.addEventListener("resize", function() {
return (() => {
window.screenWidth = document.body.clientWidth;
that.screenWidth = window.screenWidth;
console.log("that.screenWidth", that.screenWidth);
})();
});
},
watch: {
//防止因为频繁触发 resize 函数,导致页面很卡的问题
screenWidth(val) {
if (!this.timer) {
this.screenWidth = val;
this.timer = true;
let that = this;
setTimeout(function() {
that.reload();
that.timer = false;
}, 400);
}
}
}
以上是编程学习网小编为您介绍的“vuejs监听当前浏览器大小执行”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:vuejs监听当前浏览器大小执行


基础教程推荐
猜你喜欢
- webpack学习笔记一:安装webpack、webpack-dev-server、内存加载js和html文件、loader处理非js文件 2023-10-29
- clientX,pageX,offsetX,x,layerX,screenX,offsetLeft区别分析 2024-01-08
- Django操作cookie的实现 2024-04-15
- Bootstrap学习笔记之css组件(3) 2024-01-22
- js判断一个对象是否在一个对象数组中(场景分析) 2022-10-21
- 创建Vue3.0需要安装哪些脚手架 2025-01-16
- 纯css实现漂亮又健壮的tooltip的方法 2024-01-23
- JSONObject与JSONArray使用方法解析 2024-02-07
- html5视频如何嵌入到网页(视频代码) 2025-01-22
- Loaders.css免费开源加载动画框架介绍 2025-01-23