zoukankan      html  css  js  c++  java
  • 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()
          }
    
        }
      },
    
  • 相关阅读:
    Python(多进程multiprocessing模块)
    Python(队列)
    Unique Paths
    Unique Paths
    Jump Game II
    Jump Game
    Path Sum II
    Path Sum
    Remove Element
    Implement strStr()
  • 原文地址:https://www.cnblogs.com/cckui/p/10313833.html
Copyright © 2011-2022 走看看