每当我单击删除按钮时,它都可以正常工作,但我没有得到像“成功删除”这样的输出,它的显示。然后是未定义的。const deleteThisCategory = (CategoryId) => { deleteCategory(CategoryId, user._id, token).then(data => { if (data.error) { console.log(data.error); } else { preload(); } });};这是删除类别 API 调用export const deleteCategory = (userId, categoryId , token) => { fetch(`${API}/category/${categoryId}/${userId}`, { method: "DELETE", headers: { Authorization: `Bearer ${token}`, "Content-Type":"application/json" }, }) .then(response => { return response.json(); }) .catch(err => console.log(err));};
1 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
应该是这样的。deleteCategory 只需要发送承诺。以后无论你在哪里解决,你都必须使用 then。
export const deleteCategory = (userId, categoryId , token) => {
return fetch(`${API}/category/${categoryId}/${userId}`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type":"application/json"
}
})
};
const deleteThisCategory = (CategoryId) => {
deleteCategory(CategoryId, user._id, token).then(data => {
preload();
}).catch(err => {
console.log(err);
})
};
添加回答
举报
0/150
提交
取消