这期内容当中小编将会给大家带来有关vue中怎么监听屏幕高度,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
首先需要在data里面定义页面的高度
data (){
return {
fullHeight: document.documentElement.clientHeight
}
}
把window.onresize事件挂在到mounted
mounted() {
const that = this
window.onresize = () => {
return (() => {
window.fullHeight = document.documentElement.clientHeight
that.fullHeight = window.fullHeight
})()
}
}
监听window.onresize事件
watch: {
fullHeight (val) {
if(!this.timer) {
this.fullHeight = val
this.timer = true
let that = this
setTimeout(function (){
that.timer = false
},400)
}
}
}
上述就是小编为大家分享的vue中怎么监听屏幕高度了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注天达云行业资讯频道。