VUE项目axios请求头更改Content-Type

时间:2024-11-17 20:08:01
const httpServer = (opts, data) => {
const token = localStorage.getItem('token')
const PUBLIC = `?token=${token}`
let httpDefaultOpts = ''
var host = `${process.env.HOST}`
var prot = `${process.env.PORT}`
var base = host +(prot?":"+prot:"")
if (opts.method === 'post') {
httpDefaultOpts = {
method: opts.method,
url: `${base}${opts.url}${PUBLIC}`,
headers:{
'Content-Type':'application/text/html;charset=utf-8' //改这里就好了
},
data: data
}
} else {
httpDefaultOpts = opts
} return new Promise(function (resolve, reject) {
Axios(httpDefaultOpts).then(
(res) => {
successState(res)
resolve(res)
}
).catch(
(err) => {
errorState(err)
reject(err)
}
)
})
}