首页 > 技术文章 > 监听屏幕处理响应式操作

breakXu 2018-12-28 16:09 原文

 

 

data:{

isLeftHiden:false,

},

methods:{
togglemobileauto(ismobile){
this.isLeftHiden = ismobile
},
},

beforeMount () {
const {body} = document
const WIDTH = 768;
const RATIO = 3;
const handler = () => {
if (!document.hidden) {
let rect = body.getBoundingClientRect()
console.log(rect,7777);
let isMobile = rect.width - RATIO < WIDTH
this.togglemobileauto(isMobile)
}
}
document.addEventListener('visibilitychange', handler)
window.addEventListener('DOMContentLoaded', handler)
window.addEventListener('resize', handler);
},

推荐阅读