1.HTML
2.JS
data() {
return {
clientHeight: '',
}
},
mounted() {
// 获取浏览器可视区域高度
this.clientHeight = `${document.documentElement.clientHeight}` //document.body.clientWidth;
//console.log(self.clientHeight);
window.onresize = function temp() {
this.clientHeight = `${document.documentElement.clientHeight}`;
};
},
watch: {
// 如果 `clientHeight` 发生改变,这个函数就会运行
clientHeight: function () {
this.changeFixed(this.clientHeight)
}
},
methods: {
changeFixed(clientHeight) { //动态修改样式
console.log(clientHeight);
this.$refs.homePage.style.height = clientHeight + 'px';
console.log( this.$refs.homePage.style.height,' this.$refs.homePage.style.height')
},
}
完事