[英]Vuejs won't let me console.log within request
在我的Vue.js脚本的方法部分我试图做一个console.log但没有发生任何事情,事实上我在这部分内根本没有javascript但是'/ register'的请求仍然有效。
postRegister: function(){
//code here works fine
console.log('working')
this.$http.post('/register', this.user, function(response){
//Any code here does not work even though the request itself has worked
console.log('not working');
});
}
我的控制器
public function Register(Request $request)
{
$validator = Validator::make($request->all(), [
'username' => 'required|unique:users|max:12',
'email' => 'required|unique:users|email',
'password' => 'required|confirmed'
]);
if ($validator->fails()) {
return $validator->errors()->all();
}
}
正如我最初所说,一切正常,验证器返回正确的响应和所有内容,并且后期尝试成功完成,但是在http post请求中没有记录控制台数据!
由于您使用的是验证器,因此您无法获得200状态代码,这就是成功函数不会被触发的原因。 您应该捕获错误然后console.log它:
this.$http.post('/register', this.user)
.then(function(response){
console.log(response);
})
.catch(function(error){
console.log(error);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.