clientHeight获取屏幕可视化高度

此时你设置后会发现屏幕的高度出现滚动条
那是因为body有8个外边距 设置margin:0就可以解决

watch可以区监听data中的数据,只要data中的数据发生变化 就可以执行watch中的函数了
watch也可以区调用methods中的方法

 

  <style>
     #box{
      background: #000;
     }
     body{
      margin: 0;
     }
  </style>

 

<body>
  div id="app">
     ="box" ref="fullheight">
     
     </div>
   >
>

 

<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script>
    new Vue({

      el: '#app',data() {
          return {
             clientHeight:""this.clientHeight=`${document.documentElement.clientHeight}`;//获取屏幕可视化的高度;
           console.log(this.clientHeight);//798px
          
          window.onresize = function temp() { 屏幕大小发生改变触发 window.onresize
            this.clientHeight = `${document.documentElement.clientHeight}`;
             console.log("sf",this.clientHeight)
          };
        },watch: {
           如果 `clientHeight` 它是data中的值发生改变,这个函数就会运行
          clientHeight: function () {
            this.changeFixed(this.clientHeight);去调用methods中的函数
          }
        },methods:{
          changeFixed(clientHeight){                        动态修改样式
            console.log(clientHeight);
            this.$refs.fullheight.style.height = clientHeight+'px';
          },}
    })
  </script>

 

相关文章

https://segmentfault.com/a/1190000022018995 https://www....
ES6 (ECMAScript 6)中的模块是一个包含 JavaScript 代码的...
from https://mp.weixin.qq.com/s/-rc1lYYlsfx-wR4mQmIIQQ V...
D:\Temp&gt;npm init vite@latest vue3study --temp...
文章浏览阅读1.2k次。最近自己从零撸起的甘特图组件需要子组...
文章浏览阅读3.3k次,点赞3次,收藏16次。静默打印是什么?简...