【发布时间】:2021-01-23 12:57:52
【问题描述】:
我在使用 redux/axios 时遇到问题。我想在一个axios请求成功后改变store,在store改变之后我想改变应用状态。我希望代码能够到达我的功能,但这并没有发生,我不知道为什么! redux 是异步的吗?如果是这样,我该如何进行同步呼叫? (下面留下一些代码)
axios.post(url,{
"system":system,
})
.then(res => {
this.props.setTest(res) #code does not follow this line, no state is set
this.setState({
test_data:res,
redirect:true
})
})
.catch((error)=>{
if(error.response){
if(error.response.data["Error"]){
console.log("There was an error fetching the test")
}
}
})
export function setTest(test){
return {type: "SET_TEST",payload: test}
}
case "SET_TEST":{
console.log("SET_TEST")
return {
...state,
(and other changed args)
};
}
感谢您的帮助!
【问题讨论】: