1、400狀態碼
400的主要有兩種形式:
(1)、bad request意思是“錯誤的請求";
(2)、invalid hostname意思是"不存在的域名”。
2、axios
axios默認的請求頭的格式是:
application/json
若后端的請求頭是:
application/x-www-form-urlencoded
application/x-www-form-urlencoded表示:
數據被編碼為名稱/值對。這是標准的編碼格式。
若前端發送post請求時的參數以json格式發送就會報400,
this.$http.post({ url:'/v1/assets', data:{ name: this.form.name, categoryType: this.form.type, categoryName: this.form.type === "power" ? "電源" : "其他配件", fee: 123.5, factoryId: 1 }
修改方法:對請求的參數進行 序列化成URL形成發送。
使用qs庫的qs.stringify方法即可。