I added Axios to my Vue app via Vue UI dependency installation. I would like to access Axios within my components by using
this.$http.myHTTPmethod
So I created http.js based on this documentation
https://github.com/axios/axios#axioscreateconfig
import axios from "axios";
const devInstance = createInstance("http://localhost:3000");
const productionInstance = createInstance("http://localhost:3000"); // will change later
function createInstance(baseURL){
return axios.create({
baseURL,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${localStorage.token}`
}
});
}
export default devInstance; // Check debug/build mode
My question:
How can I make axios use this axios instance? And how can I access this instance via this.$http like I would do with the Vue-Router (this.$router)?