520future

VUE.JS

# 窗口发生变化时,获取当前窗口的高度。

方案一:

  mounted () {
    const that = this;
    window.onresize = () => {
      return (() => {
        that.screenHeight = window.innerHeight
      })()
    }
  },
  data(){
    return {
      screenHeight: window.innerHeight,
    }
  }

 方案二:

export default {
   data(){
     return {
       screenHeight: window.innerHeight,
     }
   },
    mounted() {
        window.addEventListener(\'resize\', this.onResize);
    },
    beforeDestroy() {
        window.removeEventListener("resize", this.onResize);
    },
    methods: {
        onResize() {
            this.screenHeight = window.innerHeight;
        }
    }
}

 

分类:

技术点:

相关文章:

  • 2021-11-27
  • 2021-11-27
  • 2022-12-23
  • 2021-12-23
  • 2021-12-06
  • 2022-02-08
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2023-02-20
  • 2021-07-31
  • 2021-08-27
  • 2021-11-18
相关资源
相似解决方案