vue 監聽頁面寬度變化 和 鍵盤事件


vue 監聽頁面窗口大小

export default {
  name: 'Full',
  components: {
    Header,
    Siderbar 
  },
  data () {
    return {
      screenWidth: document.body.clientWidth, // 屏幕寬度
      timer: false
    }
  },
  computed: { 
    isCollapse: {
      get () {
        return this.screenWidth < 768
      },
      set () {
      }
    }
  },
  watch: {
    screenWidth (val) {
      if (!this.timer) {
        this.screenWidth = val
        if (this.screenWidth < 768) {
          this.isCollapse = true
        }
        this.timer = true
        let that = this
        setTimeout(function () {
          that.timer = false
        }, 400)
      }
    }
  }, 
  mounted () {
    // 監聽窗口大小
    window.onresize = () => {
      return (() => {
        this.screenWidth = document.body.clientWidth
      })()
    }
  },
  methods: {
    changeMenu () {
      this.isCollapse = !this.isCollapse
    }
  }
}

vue enter 事件

 created () {
    document.onkeyup = (e) => {
      if (e.keyCode === 13) {
        this.fun()
      }

    }
  },


免責聲明!

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



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