Axios get request returned undefined

vue-cli is configured with axios,post request. No problem. Get request will return undefined, for advice

/ / return a Promise (send get request)

export function fetchGet (url, param) {
return new Promise((resolve, reject) => {
axios.get(url, {params: param})
  .then(response => {
    resolve(response.data)
  }, err => {
    reject(err)
  })
  .catch((error) => {
    reject(error)
  })
})
}

/ / Encapsulation api

getBankName (p) {
return fetchGet("api/rong360BankName", p)
}

calls this API, and the returned undefined, shows that the interface is called successfully

  async choicesBankName () {
  const aa = await api.getBankName()
  console.log(aa)
},

clipboard.png

clipboard.png
finally, I wish you all a happy Valentine"s Day, and programmers who have to type code on Valentine"s Day

Apr.14,2021

has been solved, it is the configuration problem of the response interceptor, thanks to the god upstairs


you have a problem with this place, so you have written an extra err when defining it.

multiple parameters cannot be written into multiple arrow functions. As a result, see figure 2. The source of your undefined is shown in figure 3. Because you have been reject, you get undefined

.

clipboard.png

clipboard.png

clipboard.png


axios.get promise


responseresponse.data undefiend

if config is set to transformResponse transformation without return data, then the value of data is empty. This inconspicuous configuration simply cannot be matched blindly. Or will you cheat for half a day

Menu