Comparing version 3.3.7 to 3.4.0
@@ -1,1 +0,1 @@ | ||
function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}!function(e,o){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e="undefined"!=typeof globalThis?globalThis:e||self).VueAxios=o()}(this,(function(){"use strict";function e(o,n){if(!e.installed)if(n){if(e.installed=!0,o.version&&o.version.split(".")[0]<3)Object.defineProperties(o.prototype,{axios:{get:function(){return n}},$http:{get:function(){return n}}});else{if(!(o.version&&o.version.split(".")[0]>=3))return void console.error("Unknown Vue version");o.config.globalProperties.axios=n,o.config.globalProperties.$http=n}o.axios=n,o.$http=n}else console.error("You have to install axios")}return"object"==("undefined"==typeof exports?"undefined":_typeof(exports))?module.exports=e:"function"==typeof define&&define.amd?define([],(function(){return e})):window.Vue&&window.axios&&window.Vue.use&&Vue.use(e,window.axios),e})); | ||
function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}!function(e,o){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e="undefined"!=typeof globalThis?globalThis:e||self).VueAxios=o()}(this,(function(){"use strict";function e(i,f){if(!e.installed){var r,u=t(f)?{axios:r=f,$http:r}:f;if("object"===_typeof(s=u)&&Object.keys(s).every((function(e){return t(s[e])}))){var s;e.installed=!0;var c=function(e){return e&&e.version&&Number(e.version.split(".")[0])}(i);if(c){var p=c<3?o:n;Object.keys(u).forEach((function(e){p(i,e,u[e])}))}else console.error("[vue-axios] unknown Vue version")}else console.error("[vue-axios] configuration is invalid, expected options are either <axios_instance> or { <registration_key>: <axios_instance> }")}}function o(e,o,n){Object.defineProperty(e.prototype,o,{get:function(){return n}}),e[o]=n}function n(e,o,n){e.config.globalProperties[o]=n,e[o]=n}function t(e){return e&&"function"==typeof e.get&&"function"==typeof e.post}return"object"==("undefined"==typeof exports?"undefined":_typeof(exports))?module.exports=e:"function"==typeof define&&define.amd?define([],(function(){return e})):window.Vue&&window.axios&&window.Vue.use&&Vue.use(e,window.axios),e})); |
@@ -1,1 +0,1 @@ | ||
function _typeof(o){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o})(o)}function plugin(o,e){if(!plugin.installed)if(e){if(plugin.installed=!0,o.version&&o.version.split(".")[0]<3)Object.defineProperties(o.prototype,{axios:{get:function(){return e}},$http:{get:function(){return e}}});else{if(!(o.version&&o.version.split(".")[0]>=3))return void console.error("Unknown Vue version");o.config.globalProperties.axios=e,o.config.globalProperties.$http=e}o.axios=e,o.$http=e}else console.error("You have to install axios")}"object"==("undefined"==typeof exports?"undefined":_typeof(exports))?module.exports=plugin:"function"==typeof define&&define.amd?define([],(function(){return plugin})):window.Vue&&window.axios&&window.Vue.use&&Vue.use(plugin,window.axios);export{plugin as default}; | ||
function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function plugin(e,n){if(!plugin.installed){var o=isAxiosLike(n)?migrateToMultipleInstances(n):n;if(isValidConfig(o)){plugin.installed=!0;var i=getVueVersion(e);if(i){var t=i<3?registerOnVue2:registerOnVue3;Object.keys(o).forEach((function(n){t(e,n,o[n])}))}else console.error("[vue-axios] unknown Vue version")}else console.error("[vue-axios] configuration is invalid, expected options are either <axios_instance> or { <registration_key>: <axios_instance> }")}}function registerOnVue2(e,n,o){Object.defineProperty(e.prototype,n,{get:function(){return o}}),e[n]=o}function registerOnVue3(e,n,o){e.config.globalProperties[n]=o,e[n]=o}function isAxiosLike(e){return e&&"function"==typeof e.get&&"function"==typeof e.post}function migrateToMultipleInstances(e){return{axios:e,$http:e}}function isValidConfig(e){return"object"===_typeof(e)&&Object.keys(e).every((function(n){return isAxiosLike(e[n])}))}function getVueVersion(e){return e&&e.version&&Number(e.version.split(".")[0])}"object"==("undefined"==typeof exports?"undefined":_typeof(exports))?module.exports=plugin:"function"==typeof define&&define.amd?define([],(function(){return plugin})):window.Vue&&window.axios&&window.Vue.use&&Vue.use(plugin,window.axios);export{plugin as default}; |
{ | ||
"name": "vue-axios", | ||
"version": "3.3.7", | ||
"version": "3.4.0", | ||
"description": "A small wrapper for integrating axios to Vuejs", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue-axios.esm.min.js", |
@@ -11,3 +11,3 @@ # vue-axios | ||
## Why | ||
## Why | ||
@@ -100,3 +100,3 @@ I created this library because, in the past, I needed a simple solution to migrate from `vue-resource` to `axios`. | ||
```js | ||
```ts | ||
// main.ts | ||
@@ -135,2 +135,77 @@ import { createApp } from 'vue' | ||
Please kindly check full documention of [axios](https://github.com/axios/axios) too | ||
Please kindly check full documentation of [axios](https://github.com/axios/axios) too | ||
## Multiple axios instances support | ||
The library allows to have different version of axios at the same time as well as change the default registration names (e.g. `axios` and `$http`). To use this feature you need to provide options like an object where: | ||
- `<key>` is registration name | ||
- `<value>` is instance of axios | ||
For Vue it looks like this: | ||
```js | ||
// Vue 2 / Vue 3 + Composition API | ||
import App from './App.vue' | ||
import VueAxios from 'vue-axios' | ||
import axios from 'axios' | ||
import axios2 from 'axios' | ||
Vue.use(VueAxios, { $myHttp: axios, axios2: axios2 }) // or app.use() for Vue 3 Optiona API | ||
// usage | ||
export default { | ||
methods: { | ||
getList(){ | ||
this.$myHttp.get(api).then((response) => { | ||
console.log(response.data) | ||
}) | ||
this.axios2.get(api).then((response) => { | ||
console.log(response.data) | ||
}) | ||
} | ||
} | ||
} | ||
``` | ||
It works similarly in Options API of Vue 3 but if you want to use Composition API you should adjust your code a bit to extract proper keys, e.g.: | ||
```ts | ||
// Vue 2 + Setup function | ||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
import store from './store' | ||
import axios from 'axios' | ||
import VueAxios from 'vue-axios' | ||
const app = createApp(App).use(store) | ||
app.use(VueAxios, { $myHttp: axios, axios2: axios2 }) | ||
app.provide('$myHttp', app.config.globalProperties.$myHttp) // provide '$myHttp' | ||
app.provide('axios2', app.config.globalProperties.axios2) // provide 'axios2' | ||
app.mount('#app') | ||
// App.vue | ||
import { inject } from 'vue' | ||
export default { | ||
name: 'Comp', | ||
setup() { | ||
const $myHttp: any = inject('$myHttp') // inject $myHttp | ||
const getListWithMyHttp = (): void => { | ||
$myHttp | ||
.get(api) | ||
.then((response: { data: any }) => { | ||
console.log(response.data) | ||
}); | ||
}; | ||
const axios2: any = inject('axios2') // inject axios2 | ||
const getListWithAxios2 = (): void => { | ||
axios2 | ||
.get(api) | ||
.then((response: { data: any }) => { | ||
console.log(response.data) | ||
}); | ||
}; | ||
return { getListWithMyHttp, getListWithAxios2 } | ||
} | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11332
209