vue---監聽瀏覽器窗口的寬度


使用VUE開發后台項目,后台項目需要進行后台根據瀏覽器窗口進行變化,需要使用vue來監聽瀏覽器的窗口變化。

<template>
    <div class="content" :style="height"></div>
</template>

<script>
export default {
  name: 'App',
  data () {
  return {
      height:'',
  }
  },
  components:{},
  methods:{
    getHeight(){
      this.height = window.innerHeight - 70 + 'px';
    }
  },
  created(){
    window.addEventListener('resize', this.getHeight);
    this.getHeight()
  },
  destroyed(){
    window.removeEventListener('resize', this.getHeight)
  }
}
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM