Axios Headers
-
Hello guys im having trouble setting axios headers to get token from localstorage,which file do i set that
-
I set the default properites for axios in the boot file set up by Quasar CLI under src/boot/axios.js. Place the code inside the exported default function.
export default async ({ Vue }) => { axios.defaults.headers.common['Accept'] = 'application/json'; Vue.prototype.$axios = axios }
-
@nqaba
In my case this file is under
/src/plugins/axios.jsimport { LocalStorage } from 'quasar'; // make sure you edit quasar.conf.js import axios from 'axios'; export default ({ app, router, Vue }) => { axios.defaults.baseURL = 'https://api.somewhere.com/'; // Add a response interceptor axios.interceptors.response.use(function (response) { // Do something with response data // Loading.hide(); return response; }, function (error) { // Do something with response error return Promise.reject(error); }); axios.interceptors.request.use(function (config) { // default options // Loading.show(); return config; }); axios.defaults.method = 'POST'; axios.defaults.transformRequest = [function (data, headers) { // Do whatever you want to transform the data return data; }]; // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; axios.defaults.headers.post['Content-Type'] = 'application/json'; // axios.defaults.headers.common['Authorization'] = AUTH_TOKEN; Vue.prototype.$axios = axios; // window.$axios = axios; super super super global : ) };
in quasar.conf.js
// Quasar plugins plugins: [ 'Notify', 'SessionStorage', 'LocalStorage', /** this line **/ 'Dialog',
-
-
Thanks a lot guys
-
This post is deleted!