发生这种情况的原因可能是您
this没有指向正确的范围,而是在
$.ajax调用中更改了范围,因此您只需要执行以下操作即可:
methods: { onLogin: function() { //this.$set(loginSubmit, 'Logging In...'); var data = { email: $('#email').val(), password: $('#password').val(), }; var that = this $.ajax({ url: '/api/login', data: data, method: 'POST' }).then(function (response) { if(response.error) { console.err("There was an error " + response.error); that.loginError = 'Error'; } else { //$('#loginBlock').attr("hidden",true); console.log(response.user); if(response.user) { that.isLoggedIn = true; } else { that.loginError = 'User not found'; } } }).catch(function (err) { console.error(err); }); } }


