vue 动态获取当前浏览器内容高度并赋值给元素

常用的方法:

高度:

document.documentElement.clientHeight
738px

宽度:
document.documentElement.clientWidth
886px

效果图:

不废话,贴代码了:

<template>

            <div class="hello">
              <div  :style="height"></div>
            </div>

</template>

 

<script>

export default {
name: 'hello',
data () {
  return {
    height:{
      width:'200px',
      height:'',
      background:'red',
    }
  }
},
components:{
},
created(){
  this.hh();
},
methods:{
      hh(){
        this.height.height = (window.innerHeight)*0.69 + 'px';
            console.log("this.height.height",this.height.height);
      }
    }
}

</script>

猜你喜欢

转载自blog.csdn.net/qq_41646249/article/details/89491869
今日推荐