您的位置:首页 > 产品设计 > UI/UE

ajax 或者 axios 或调函数中 指向vue 实例

2017-02-20 11:04 876 查看
1.箭头函数 (resp) => {//函数体}

或者

function (res) {}.bind(this) 


axios.post('/app/user/loginSubmit',data)
.then(function(res){
if(res.data){
this.error = '';
window.location.href = '/';
}else {
this.error = '帐号或者密码错误';
}
//console.log(res);
}.bind(this))
.catch(function(err){
//console.log(err);
});

axios.post('/app/user/loginSubmit',data)
.then((res)=>{
if(res.data){
this.error = '';
window.location.href = '/';
}else {
this.error = '帐号或者密码错误';
}
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: