使用axios處理請求時,出現的問題解決
當url是遠程接口鏈接時,會報404的錯誤:
Uncaught (in promise) Error: Request failed with status code 404
解決方法:
var instance = axios.create({ headers: {'content-type': 'application/x-www-form-urlencoded'} }); instance.post(`url`, params).then(res => res.data);
后台接收不到傳入參數解決方法:
var qs=require('qs'); var instance = axios.create({ headers: {'content-type': 'application/x-www-form-urlencoded'} }); instance.post(`url`, qs.stringify(params)).then(res => res.data);