當(dāng)前位置:首頁(yè) > IT技術(shù) > 移動(dòng)平臺(tái) > 正文

axios設(shè)置請(qǐng)求頭實(shí)現(xiàn)post請(qǐng)求發(fā)送數(shù)據(jù)的格式(Form Data)
2021-09-17 16:35:27

common.js:

common函數(shù)傳遞的參數(shù)添加?contentType:?'application/x-www-form-urlencoded'?即可改變post請(qǐng)求參數(shù)傳遞的格式

import axios from 'axios'
import qs from 'qs'

const service = axios.create()


export const common = async (config) => {
  if (config.contentType === 'application/x-www-form-urlencoded') {
    config.headers = { 'content-type': 'application/x-www-form-urlencoded' }
    config.data = qs.stringify(config.data)
  }
  let res = await service(config)
  return res
}

?

?
?
?
?

本文摘自 :https://blog.51cto.com/x

開(kāi)通會(huì)員,享受整站包年服務(wù)立即開(kāi)通 >