瀟湘沐
2023-05-25 17:38:14
每當我單擊刪除按鈕時,它都可以正常工作,但我沒有得到像“成功刪除”這樣的輸出,它的顯示。然后是未定義的。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 只需要發(fā)送承諾。以后無論你在哪里解決,你都必須使用 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
提交
取消