Uncaught (in promise) TypeError: Cannot read property ‘$confirm‘ of undefined at eval (Login.vue

想要用element ui的message box提示用户名不存在,询问用户是否注册,可是控制台报错

 methods: {
      login() {
        var that=this
        this.$refs.ruleForm.validate((valid) => {
          if (valid) {
            // 向后端发起请求,提交数据
            this.$axios.post('http://localhost:9090/login',{
              username:this.submitForm.username,
              password:this.submitForm.password
            }).then(function (response){
              console.log(response)
              if (response.data!=""){
                console.log(response.data)
                alert("登陆成功!")
                that.$router.push({
                  path:'/personal_center'
                })
              }
              else{
                const confirmRes=that.$confirm("用户名不存在!是否注册?",{
                  confirmButtonText:'注册',
                  confirmButtonText:'再试试登录',
                  type:'warning'
                }).then((action)=>{
                  if(action === 'confirm'){
                    that.$router.push({
                      path:'/regist'
                    })
                  }
                }).catch(()=>{
                  this.$message({
                    message:'请重新登录!'
                  })
                })

              }

            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }

把this. c o n f i r m ( " 用 户 名 不 存 在 ! 是 否 注 册 ? " 改 为 上 图 代 码 中 t h a t . confirm("用户名不存在!是否注册?"改为上图代码中that. confirm(""that.confirm("用户名不存在!是否注册?"就可以了。
好像是因为.then(function (response)是匿名函数不是箭头函数,this改变指向了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值