实现效果:

vue.js获取屏幕高度clientHeight设置充满屏幕引导页

方法:

html:

vue.js获取屏幕高度clientHeight设置充满屏幕引导页

JS:

<script>
  export default {
    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';

      },
    }
  }
</script>
获取clientHeight高度,监听发生变化时执行changeFixed函数动态修改样式





相关文章:

  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2022-01-08
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2021-11-18
  • 2022-01-08
  • 2021-11-18
  • 2022-01-07
  • 2022-01-08
相关资源
相似解决方案