axios-vue
Integrate axios in Vue.js project as a Vue Plugin.
What and Why?
Tired of integrating axios in Vue.js projects time to time. This plugin package adds axios as a dependency and installed to Vue with some initializations.
Usage
Install
npm i axios-vue -S
Init in Vue projects' main or index file
Vue // You can also declare global default configs and instance configs in plugin options.Vue // Two ways for interceptors declarationaxiosVue { return config}axiosVue { return Promise}axiosVue { return response}axiosVue { return Promise} // orVue// If both two ways are used, methods in options will override those outer fns.// Actually, the four functions above will be set by default in this plugin.
The usage in Vue components
// Same as axios()thisthis// Can get axios instance on Vue constructorVueVue // Same as methods(get, post, put etc.) on axiosthis$httpthis$axiosVue$httpVue$axios