【发布时间】:2019-04-15 22:27:51
【问题描述】:
当我在 func2 中调用 this.func1() 时,func1 返回 undefined。 有人帮助我吗? 我认为 func 什么都没有返回,因为 axios 没有完成,我该如何解决这个问题?
func1:function(val){
if(val.x == 0)
{
axios.post('/...', {
})
.then((response) => {
if(response.data == 0)
{
return true;
}
else
{
return false
}
})
.catch((error) => {
return false;
});
}
else
{
return false;
}
}
//////
//////
//////
func2:function(variable){
console.log(this.func1(variable)) // undefined..
if(this.func1(variable) == true)
{
}
}
【问题讨论】:
-
function1 是异步函数。