{"id":13494104,"url":"https://github.com/imcvampire/vue-axios","last_synced_at":"2025-05-14T00:06:28.177Z","repository":{"id":12458017,"uuid":"71871673","full_name":"imcvampire/vue-axios","owner":"imcvampire","description":"A small wrapper for integrating axios to Vuejs","archived":false,"fork":false,"pushed_at":"2024-06-18T15:37:24.000Z","size":3358,"stargazers_count":2011,"open_issues_count":11,"forks_count":181,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-05-10T10:36:37.210Z","etag":null,"topics":["axios","hacktoberfest","integrating-axios","vue-axios","vuejs","wrapper"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/vue-axios","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imcvampire.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-25T07:39:39.000Z","updated_at":"2025-05-09T13:58:35.000Z","dependencies_parsed_at":"2023-11-11T18:27:32.555Z","dependency_job_id":"11cb570a-64ba-4d56-898d-5999501db075","html_url":"https://github.com/imcvampire/vue-axios","commit_stats":{"total_commits":155,"total_committers":14,"mean_commits":"11.071428571428571","dds":0.4903225806451613,"last_synced_commit":"990cacb197c3943c236725b82ebb8a94ac11dce2"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcvampire%2Fvue-axios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcvampire%2Fvue-axios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcvampire%2Fvue-axios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imcvampire%2Fvue-axios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imcvampire","download_url":"https://codeload.github.com/imcvampire/vue-axios/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253678772,"owners_count":21946314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axios","hacktoberfest","integrating-axios","vue-axios","vuejs","wrapper"],"created_at":"2024-07-31T19:01:21.891Z","updated_at":"2025-05-14T00:06:28.157Z","avatar_url":"https://github.com/imcvampire.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","实用库","Awesome Vue.js [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)"],"sub_categories":["Libraries \u0026 Plugins"],"readme":"# vue-axios\n\n[![npm version](https://img.shields.io/npm/v/vue-axios.svg?style=flat-square)](https://www.npmjs.org/package/vue-axios)\n[![install size](https://packagephobia.now.sh/badge?p=vue-axios)](https://packagephobia.now.sh/result?p=vue-axios)\n[![npm downloads](https://img.shields.io/npm/dm/vue-axios.svg?style=flat-square)](http://npm-stat.com/charts.html?package=vue-axios)\n[![jsdelivr](https://data.jsdelivr.com/v1/package/npm/vue-axios/badge?style=rounded)](https://www.jsdelivr.com/package/npm/vue-axios)\n[![License](https://img.shields.io/npm/l/vue-axios.svg)](https://www.npmjs.com/package/vue-axios)\n\nA small wrapper for integrating axios to Vuejs\n\n## Why\n\nI created this library because, in the past, I needed a simple solution to migrate from `vue-resource` to `axios`.\n\nIt only binds axios to the `vue` instance so you don't have to import everytime you use `axios`.\n\n## How to install:\n### ES6 Module:\n```bash\nnpm install --save axios vue-axios\n```\nImport libraries in entry file:\n```js\n// import Vue from 'vue'   // in Vue 2\nimport * as Vue from 'vue' // in Vue 3\nimport axios from 'axios'\nimport VueAxios from 'vue-axios'\n```\n\nUsage in Vue 2:\n```js\nVue.use(VueAxios, axios)\n```\n\nUsage in Vue 3:\n```js\nconst app = Vue.createApp(...)\napp.use(VueAxios, axios)\n```\n\n### Script:\nJust add 3 scripts in order: `vue`, `axios` and `vue-axios` to your `document`.\n\n## Usage:\n\n### in Vue 2\n\nThis wrapper bind `axios` to `Vue` or `this` if you're using single file component.\n\nYou can use `axios` like this:\n```js\nVue.axios.get(api).then((response) =\u003e {\n  console.log(response.data)\n})\n\nthis.axios.get(api).then((response) =\u003e {\n  console.log(response.data)\n})\n\nthis.$http.get(api).then((response) =\u003e {\n  console.log(response.data)\n})\n```\n\n### in Vue 3\n\nThis wrapper bind `axios` to `app` instance or `this` if you're using single file component.\n\nin option API, you can use `axios` like this:\n\n```js\n// App.vue\nexport default {\n  name: 'App',\n  methods: {\n    getList() {\n      this.axios.get(api).then((response) =\u003e {\n        console.log(response.data)\n      })\n      // or\n      this.$http.get(api).then((response) =\u003e {\n        console.log(response.data)\n      })\n    }\n  }\n}\n```\n\nhowever, in composition API `setup` we can't use `this`, you should use `provide` API to share the globally instance properties first, then use `inject` API to inject `axios` to `setup`:\n\n```ts\n// main.ts\nimport { createApp } from 'vue'\nimport App from './App.vue'\nimport store from './store'\nimport axios from 'axios'\nimport VueAxios from 'vue-axios'\n\nconst app = createApp(App).use(store)\napp.use(VueAxios, axios)\napp.provide('axios', app.config.globalProperties.axios)  // provide 'axios'\napp.mount('#app')\n\n// App.vue\nimport { inject } from 'vue'\n\nexport default {\n  name: 'Comp',\n  setup() {\n    const axios: any = inject('axios')  // inject axios\n\n    const getList = (): void =\u003e {\n      axios\n        .get(api)\n        .then((response: { data: any }) =\u003e {\n          console.log(response.data)\n        });\n    };\n\n    return { getList }\n  }\n}\n```\n\nPlease kindly check full documentation of [axios](https://github.com/axios/axios) too\n\n## Multiple axios instances support\n\nThe 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:\n- `\u003ckey\u003e` is registration name\n- `\u003cvalue\u003e` is instance of axios\n\nFor Vue it looks like this:\n```js\n// Vue 2 / Vue 3 + Composition API\nimport App from './App.vue'\nimport VueAxios from 'vue-axios'\nimport axios from 'axios'\nimport axios2 from 'axios'\nVue.use(VueAxios, { $myHttp: axios, axios2: axios2 }) // or app.use() for Vue 3 Optiona API\n\n// usage\nexport default {\n  methods: {\n    getList(){\n      this.$myHttp.get(api).then((response) =\u003e {\n        console.log(response.data)\n      })\n      this.axios2.get(api).then((response) =\u003e {\n        console.log(response.data)\n      })\n    }\n  }\n}\n```\nIt 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.:\n```ts\n// Vue 2 + Setup function\nimport { createApp } from 'vue'\nimport App from './App.vue'\nimport store from './store'\nimport axios from 'axios'\nimport VueAxios from 'vue-axios'\n\nconst app = createApp(App).use(store)\napp.use(VueAxios, { $myHttp: axios, axios2: axios2 })\napp.provide('$myHttp', app.config.globalProperties.$myHttp)  // provide '$myHttp'\napp.provide('axios2', app.config.globalProperties.axios2)  // provide 'axios2'\napp.mount('#app')\n\n// App.vue\nimport { inject } from 'vue'\n\nexport default {\n  name: 'Comp',\n  setup() {\n    const $myHttp: any = inject('$myHttp')  // inject $myHttp\n\n    const getListWithMyHttp = (): void =\u003e {\n      $myHttp\n        .get(api)\n        .then((response: { data: any }) =\u003e {\n          console.log(response.data)\n        });\n    };\n\n    const axios2: any = inject('axios2')  // inject axios2\n    const getListWithAxios2 = (): void =\u003e {\n      axios2\n        .get(api)\n        .then((response: { data: any }) =\u003e {\n          console.log(response.data)\n        });\n    };\n\n\n    return { getListWithMyHttp, getListWithAxios2 }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcvampire%2Fvue-axios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimcvampire%2Fvue-axios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimcvampire%2Fvue-axios/lists"}