使用方式如下:

mounted() {
  window.onresize = () => {
    return (() => {
      this.$nextTick(() => {
        console.log('this.$refs.wrapper', this.$refs.wrapper)
      })
    })()
  }
},

注意:
createdmounted中监听都可以,但是在created监听的话此时的document还没有生成,请根据实际需求来实现,添加$nextTick()也是确保此时的DOM已经加载完成。

Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐