3 回答

TA貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個贊
代碼在 Content-Type 中聲明主體將是 URL 字符串編碼的,但在主體中它被賦予了一個 JavaScript 對象。似乎 Axios 客戶端不會將該 body 對象轉(zhuǎn)換為 url 編碼值(即 from?{a: 5, b: 2}
to?"a=5&b=2"
)。代碼需要一個函數(shù)來轉(zhuǎn)換它。一個流行的是qs。
否則,您的數(shù)據(jù)可能會被轉(zhuǎn)換為字符串,該.toString()
方法將為您提供"[object Object]"
,您應(yīng)該能夠在開發(fā)人員工具的網(wǎng)絡(luò)選項(xiàng)卡中看到這一點(diǎn)。

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個贊
Axios 處理錯誤的方式不同。
找出真正的問題所在。
您應(yīng)該使用 error.request 來檢查您提出的請求是否有錯誤
并使用 error.response 從服務(wù)器獲取錯誤反饋
axios({ method: 'post', url: 'https://app/login', body: body1, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) .then (res => { if (res.status === 200) { console.log(res) } }).catch(err => { if(err.request){ console.log(err.request) } if( err.response){ console.log(err.response) } });

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個贊
Localhost:3000/api/products 404 錯誤 您沒有在 server.js 上創(chuàng)建 res.get("/api/products") 或者您沒有設(shè)置代理。檢查下面的代理設(shè)置。
代理錯誤:無法代理請求 /api/products 檢查:
前端/package.json
{ "name": "frontend", "proxy": "http://127.0.0.1:5000", ... }
停止運(yùn)行前端和后端
先運(yùn)行后端
啟動
然后前端
cd 前端 npm start
添加回答
舉報