VUE 프로젝트 axios 요청 헤더 변경 Content-Type

1087 단어
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

좋은 웹페이지 즐겨찾기