Created
December 3, 2018 05:12
-
-
Save alexey-kar/7e9414d66a39320512b33bd1be363077 to your computer and use it in GitHub Desktop.
vue axios set header before all queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.axios.interceptors.request.use( | |
config => { | |
/* | |
const token = localStorage.getItem('token'); | |
if (token) { | |
console.log(token); | |
config.headers.Authorization = `Bearer ${token}`; | |
} else { | |
config.headers.Authorization = ''; | |
} | |
*/ | |
//config.headers['X-CSRF-TOKEN'] = $('meta[name="csrf-token"]').attr('content'); | |
return config; | |
}, | |
error => Promise.reject(error) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment