vue全局啟用 emulateJSON 選項


一、解釋

如果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('添加失敗!')
            }
          }) 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM