在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ axios catch錯誤

axios catch錯誤

    this.axios({
      method: 'POST',
      url: URL,
      data: {
        "mobile": tel,
        "auth_code": code,
        "lngLat": this.lngLat,
        "regSource": 'H5',
        "frc": "H5",
        "ref": this.ref
      },
      headers: {
        'appId': config.config.APPID,
        'token': this.token
      }
    })
      .then(function (response) {
        console.log(response)

      })
      .catch(function (error) {
        console.log(error)
      });
      
      
      console.log(error)里邊輸出
      
      
    Error: Request failed with status code 400
    at createError (createError.js?16d0:16)
    at settle (settle.js?db52:18)
    at XMLHttpRequest.handleLoad (xhr.js?ec6c:77)
    at _this.(anonymous function) (chrome-        extension://jegnjmcegcpodciadcoeneecmkiccfgi/enablecrossorigin.js:81:55)
    
    
    這樣寫哪里錯了嗎,為什么catch(err)啊
回答
編輯回答
鹿惑

axios攔截器里面,設(shè)置content-type了嗎?
后臺接收content-type:application/json;還是application/x-www-form-urlencoded或者別的,
400后臺應(yīng)該是都沒收到你的請求

2017年9月11日 18:05
編輯回答
奧特蛋

post 的data 要 JSON.stringify(bodyData)

2018年6月30日 06:31
編輯回答
她愚我

樓上說的很對,主要看后臺要求post請求可以接受什么數(shù)據(jù),axios中post默認(rèn)請求數(shù)據(jù)格式是application/json,如果后臺不支持可以
設(shè)置請求頭格式
在config配置headers: {'X-Requested-With':'XMLHttpRequest'},
格式化數(shù)據(jù)
并引入axios里面內(nèi)置的qs,不需要重新下載

import qs from 'qs'
this.axios({
      method: 'POST',
      url: URL,
      data: qs.stringify({
        "mobile": tel,
        "auth_code": code,
        "lngLat": this.lngLat,
        "regSource": 'H5',
        "frc": "H5",
        "ref": this.ref
      }),
      headers: {
        'appId': config.config.APPID,
        'token': this.token,
        'X-Requested-With':'XMLHttpRequest'
      }
    })
2017年4月10日 04:44
編輯回答
青黛色

看你后臺需要接受什么格式的數(shù)據(jù)

2018年5月20日 20:24
編輯回答
浪蕩不羈

語法格式錯誤,估計傳的參數(shù)和服務(wù)端要求的不一致造成的。

2017年7月24日 18:06