vue 浏览器宽度变化实时监听
【代码】vue 浏览器宽度变化实时监听。
·
监听页面宽度,调整显示样式
data() {
return {
screenWidth: document.body.clientWidth
}
},
watch: {
screenWidth(val) {
if (!this.timer) {
this.screenWidth = val
this.timer = true
let that = this
setTimeout(function() {
console.log(that.screenWidth)
that.timer = false
}, 400)
}
}
},
mounted() {
const that = this
window.onresize = () => {
return (() => {
window.screenWidth = document.body.clientWidth
that.screenWidth = window.screenWidth
})()
}
},
更多推荐
已为社区贡献3条内容
所有评论(0)