I am new to vue and Quasar.
Now, I got how Vue works vaguely,
I was trying to comprehend the boilerplate code which we get when we init Quasar
While initiating, I asked it to integrate axios and veux from cli
Now I was trying to comprehend the boiler plate which is when stumbled upon axios.js file inside plugin folder
The file contain the following code
import axios from 'axios'
export default ({ Vue }) => {
Vue.prototype.$axios = axios
}
Can someone tell me what does this code do? Based on my understanding, it seems like it adds a method to vue known as axios so that we can use it globally?
What could be the reason for using
$axios
? i.eVue.prototype.$axios = axios
, Can't we just doVue.prototype.axios = axios
? since it is eventually creating a property?If we can use axios globally (without importing it or in other words writing
import axios from "axios"
). Then how can we do it?I am guessing this will only work on .vue file?
I am used to creating a helper function where I do all the network request, usually the helper function file would be
networkRequest.js
where I would import axios and make requests. ThatnetworkRequest.js
is the single point from where all the requests are made. SinceVue.prototype.$axios = axios
would only work on .vue file? Does it still make sense to use axios plugin which comes in the boiler plate