【发布时间】:2020-10-31 13:56:10
【问题描述】:
我不知道在哪里调用 dispatch(setAlert()) 函数。在 axios.patch 请求之后我想要它,但目前它不起作用
let url = `.....................`;
const handleSubmit = (e) => {
e.preventDefault();
axios
.patch(url, form_data, {
headers: {
Authorization: `JWT ${localStorage.getItem("access")}`,
"content-type": "application/json",
},
})
dispatch(setAlert('Data changed successfully.', 'success'));
.then(() => axios.get(url))
.then((res) => {
console.log(res.data);
updateFormData({
...formData
})
})
.catch((err) => console.log(err));
};
【问题讨论】:
-
必须在 then 块中,高于或低于
updateFormData调用