天天看點

axios請求 解決post背景接收不到資料問題

問題描述:axios請求 get請求沒有問題,但是post背景傳回200但是就是接收不到資料;

axios請求 解決post背景接收不到資料問題

第一步:安裝qs

npm install qs
           

第二步:在封裝接口中引用并在post中運用;

import axios from 'axios'
import qs from 'querystringify'
           
export function post (url, data = {}) {
  return new Promise((resolve, reject) => {
    data = qs.stringify(data)
    axios.post(url, data)
      .then(response => {
      })
      .catch(err => {
        Toast.clear()
      })
  })
}
           

需要注意的是,頭部修改:

config.headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        }
           

這樣 就可以完美解決背景接收不到資料而報錯問題。