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

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)
            }
        )
    })
}

转载于:https://www.cnblogs.com/lml-lml/p/9316948.html

你可能感兴趣的:(VUE项目axios请求头更改Content-Type)