VUE获取屏幕高度
1.HTML2.JSdata() {return {clientHeight: '',}},mounted() {// 获取浏览器可视区域高度this.clientHeight = `${document.documentElement.clientHeight}`//document.body.clientWidth;//console.log(self.cli
·
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')
},
}
完事
更多推荐
已为社区贡献4条内容
所有评论(0)