After importing axios
to the main.js
and setting it as shown below:
Vue.prototype.$http = axios;
I no longer need to import axios
for every component. Now I can simply reference axios
in my vue components like this:
this.$http
.post(`/public/api/login`)
.then(response => {
console.log("ddddddddd",response);
})
.catch(error => {
console.log("Error is", error);
});
}
However, when attempting to use it within my store.js
file, I encounter an issue.
Cannot read property '$http' of undefined
This could be due to the fact that store.js is a JavaScript file rather than a Vue file.
So, my question now is how can I access axios
in my store.js
file?