监听屏幕处理响应式操作

 

 

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);
},

posted @ 2018-12-28 16:09  Breakpattert_阿涛  阅读(308)  评论(0编辑  收藏  举报