1
嗨我設置默認axios標頭在請求攔截器,但這些頭不能訪問另一個功能...在axios axios documentation它提到global-axios默認是全球...下面是我的示例代碼需要幫助如何在axios中設置全局標題?
axios.interceptors.request.use(function (config) {
axios.defaults.headers.accesstoken= "some_access_token"
axios.defaults.headers.client = "some_client"
axios.defaults.headers.uid = "some_uid"
return config;
},function (error) {
return Promise.reject(error);
});
在頁面加載componentDidmount執行,但愛可信默認標題是不確定的這一功能
componentDidMount: function() {
console.log(axios.defaults.headers) #its giving me undefined
axios.get("http://some_url_for_get_request.json", {
headers: {
accesstoken: axios.defaults.headers.accesstoken,
uid: axios.defaults.headers.uid,
client: axios.defaults.headers.client
}
})
}