1. 程式人生 > >axios將數據請求格式修改為application/x-www-form-urlencoded

axios將數據請求格式修改為application/x-www-form-urlencoded

enc TE amp transform class -type efault div RM

axios.defaults.headers[‘Content-Type‘] = ‘application/x-www-form-urlencoded;charset=UTF-8‘

axios.defaults.transformRequest = [data=> {
  let ret = ‘‘
  for (let it in data) {
    ret += encodeURIComponent(it) + ‘=‘ + encodeURIComponent(data[it]) + ‘&‘
  }
  return ret
}]

axios將數據請求格式修改為application/x-www-form-urlencoded