方法1:在外部定义一个值指代Vue实例

var self = this;
this.$http.get("login", {
    params: data
}).then(function(response) {
    self.$router.push('index');
}).catch(function(response) {
    console.error(response);
});

方法2:使用ES6的箭头函数实现上下文穿透

this.$http.get("login", {
    params: data
}).then((response) => {
    this.$router.push('index'); // 此处因为ES6箭头函数上下文穿透,this的上下文为外层的this,即Vue实例
}).catch(function (response) {
    console.error(response);
});

 

Logo

昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链

更多推荐