一、解釋
如果Web服務器無法處理編碼為application/json的請求,你可以啟用emulateJSON選項。
啟用該選項后,請求會以application/x-www-form-urlencoded作為Content-Type,就像普通的HTML表單一樣
二、代碼
1、全局啟用代碼
// 全局啟用 emulateJSON 選項 Vue.http.options.emulateJSON = true;
this.$http.post('api/addproduct', { name: this.name } ).then(result => { if (result.body.status === 0) { // 成功了! // 添加完成后,只需要手動,再調用一下 getAllList 就能刷新品牌列表了 this.getAllList() // 清空 name this.name = '' } else { // 失敗了 alert('添加失敗!') } })
2、沒有全局啟用代碼
this.$http.post('api/addproduct', { name: this.name }, { emulateJSON: true }).then(result => { if (result.body.status === 0) { // 成功了! // 添加完成后,只需要手動,再調用一下 getAllList 就能刷新品牌列表了 this.getAllList() // 清空 name this.name = '' } else { // 失敗了 alert('添加失敗!') } })
