我正在嘗試通過 axios 向我的 api 發送洗掉和放置請求。使用 post/get 一切正常,當我嘗試用郵遞員發送 delete/put 時,一切都很好,所以問題出在 react 應用程式上。
axios 實體:
const api = Axios.create({
baseURL: "http://localhost:8000",
timeout: 1000,
headers: {'Content-Type': 'application/json'}
});
要求:
Axios.delete("/",{index:name})
.then((response)=>{console.log(response)})
.catch((err)=>{console.log(err)});
*put 是一樣的,有另一個資料
每當我部署這些代碼時,我都會在控制臺中收到404錯誤并且服務器沒有收到請求。
uj5u.com熱心網友回復:
您沒有使用通過正確的 baseURL 創建的 axios 實體。將您的請求更改為:
api
.delete("/",{index:name})
.then((response)=>{console.log(response)})
.catch((err)=>{console.log(err)});
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/327398.html
