axios set headers in config vue js

非 Y 不嫁゛ 提交于 2020-01-04 02:42:22

问题


Right now I use axios like this:

import axios from 'axios'
axios.get(apiObjUrl,
  {
     headers: {
               'Content-type': 'application/x-www-form-urlencoded',
              }
  })
   .then(({data}) => {

How do I set global axios header? (I need to set localization header to use in all my requests)


回答1:


Use an Axios interceptor: https://github.com/mzabriskie/axios#interceptors

In config you have the request's headers.



来源:https://stackoverflow.com/questions/45541241/axios-set-headers-in-config-vue-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!