vue3中axios使用put方法,content-type=application/x-www-form-urlencoded

使用方法:

1.安装qs 

npm install qs

2. 设置content-type为application/x-www-form-urlencoded

const instance = axios.create({
    url: url,
    method: method,
    withCredentials: true,
    headers: {
      'content-type':'application/x-www-form-urlencoded'
    }
  })

3.PUT使用

if(method==='PUT') {
    return new Promise((resolve, reject) => {
      const config = {
        url: url,
        data: Qs.stringify(params),
        method: method
      } as AxiosRequestConfig
      instance(config).then(resp => {
        resolve(resp)
      }).catch(error => {
        reject(error)
      })
    })
}

猜你喜欢

转载自blog.csdn.net/Lucky_girl_wan/article/details/122072584
今日推荐