监听页面宽度,调整显示样式
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
})()
}
},