vue监听屏幕宽度

2022-02-19  本文已影响0人  苍老师的眼泪
<template>
  <div class="home">
    <div>{{width}}</div>
  </div>
</template>

<script>

export default {
  name: 'Home',
  data() {
    return {
      width: this.getHeight()
    }
  },
  methods: {
    getHeight() {
      this.width = document.body.clientWidth
    }
  },

  created() {
    window.addEventListener('resize', this.getHeight);
    this.getHeight()
  },

  destroyed() {
    window.removeEventListener('resize', this.getHeight);

  }


}
</script>

上一篇 下一篇

猜你喜欢

热点阅读