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

来源:互联网 发布:金星秀停播原因知乎 编辑:程序博客网 时间:2024/05/24 07:01
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 = '帐号或者密码错误';            }        })
0 0
原创粉丝点击