Vue使用回车登录的时候报 Uncaught TypeError: Cannot read properties of undefined (reading 'validate')

错误代码: created() { // 按下回车执行登录按钮点击事件 var _self = this document.onkeydown = function(e) { var key = window.event.keyCode if (key == 13) { _self.handleLogin(this.ruleForm) } } }, 正确代码: created() { // 按下回

错误代码:
    created() {
    // 按下回车执行登录按钮点击事件
    var _self = this
    document.onkeydown = function(e) {
      var key = window.event.keyCode
      if (key == 13) {
        _self.handleLogin(this.ruleForm)
      }
    }
  },
正确代码:
created() {
    // 按下回车执行登录按钮点击事件
    var _self = this
    document.onkeydown = function(e) {
      var key = window.event.keyCode
      if (key == 13) {
        _self.handleLogin('ruleForm')  //主要问题出在这里
      }
    }
  },
 

本文标题为:Vue使用回车登录的时候报 Uncaught TypeError: Cannot read properties of undefined (reading 'validate')

基础教程推荐