vue监听浏览器高度变化
1、设置变量:data() {return {clientHeight: document.documentElement.clientHeight}}2、页面初始化时给onresize函数赋值:mounted() {window.onresize = () => {this.clientHeight = d...
·
1、设置变量:
data() {
return {
clientHeight: document.documentElement.clientHeight
}
}
2、页面初始化时给onresize函数赋值:
mounted() {
window.onresize = () => {
this.clientHeight = document.documentElement.clientHeight;
}
}
3、使用watch监听变量值得变化:
watch: {
clientHeight(newValue, oldValue) {
if(newValue) {
console.log(this.clientHeight);
}
}
}
更多推荐
已为社区贡献10条内容
所有评论(0)