common.js:
common函数传递的参数添加 contentType: 'application/x-www-form-urlencoded' 即可改变post请求参数传递的格式
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