2 回答
![?](http://img1.sycdn.imooc.com/5458502c00012d4a02200220-100-100.jpg)
TA贡献1848条经验 获得超10个赞
您可以像这样添加一个已安装的 () 实例。
mounted (){
this.check_login()
},
methods:{
check_login(){
axios.get(this.url+'login/check').then(function(response){
vue.login_result = response.data.status;
})
return this.login_result;
},
insert(){
let login_result = this.check_login();
if (!login_result) {
alert('you are not login');
}else{
//ajax insert here
}
},
}
页面加载时首先运行 check_login 方法
![?](http://img1.sycdn.imooc.com/54585050000156a302200220-100-100.jpg)
TA贡献1998条经验 获得超6个赞
为什么不使用 ES6 异步等待?类似的东西
methods:{
async check_login(){
return axios.get(this.url+'login/check').then((response)=>
response.data.status;
)
},
async insert(){
let login_result = await this.check_login();
if (!login_result) {
alert('you are not login');
}else{
//ajax insert here
}
},
}
毕竟你可以在 vue 方法中声明异步函数。
添加回答
举报