亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

代碼正在運行,但我沒有得到所需的輸出

代碼正在運行,但我沒有得到所需的輸出

瀟湘沐 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 只需要發送承諾。以后無論你在哪里解決,你都必須使用 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);

    })

};


查看完整回答
反對 回復 2023-05-25
  • 1 回答
  • 0 關注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號