vue项目里登录界面实现回车登录

全局监听enter键,是把监听事件绑定到document上,无需获取焦点之类的

created() {
    let that = this;
    document.onkeydown =function(e){
      e = window.event || e;
      if(that.$route.path=='/login'&&(e.code=='Enter'||e.code=='enter')){//验证在登录界面和按得键是回车键enter
        that.submitForm('loginForm');//登录函数
      }
    }
  }

猜你喜欢

转载自www.cnblogs.com/aidixie/p/10722215.html