Post can';t修改";全局变量";在axios中调用
我有下一个JSX代码Post can';t修改";全局变量";在axios中调用,post,var,axios,Post,Var,Axios,我有下一个JSX代码 let answer = true; var postAxios = axios({ method: 'post', url: httpLink, params: {table: tableName}, data: rowInfo } )
let answer = true;
var postAxios = axios({
method: 'post',
url: httpLink,
params: {table: tableName},
data: rowInfo
}
)
.then(function (response) {
console.log(response);
alert(response);
answer = true;
})
.catch(function (error) {
console.log(error);
alert(error);
answer = false;
});
return answer;
在answer的最终值上,一些事务需要继续(answer==true)或停止(answer==false)。我的问题是,当执行catch部分时,答案总是真的。有什么办法可以解决这个问题吗?您的问题是一个“经典”问题的变体,它基于对异步编程工作原理的误解。请参阅可能的副本