vue | Npm axios
AsmallwrapperforintegratingaxiostoVuejsWhyIcreatedthislibrarybecause,inthepast,Ineededasimplesolutiontomigratefromvue-resourcetoaxios.Itonlybindsaxiostothevueinstancesoyoudonthavetoimporteverytimeyouuseaxios.SupportmatrixVueJSVueAxios1.x2.x3.x1.x✔✔✔2.x✔✔✔3.x❌❌✔Howtoinstall:ES6Module:npminstall--saveaxiosvue-axiosImportlibrariesinentryfile://importVuefromvue//inVue2import*asVuefromvue//inVue3importaxiosfromaxiosimportVueAxiosfromvue-axiosUsageinVue2:UsageinVue3:constapp=Vue.createApp(...)app....
A small wrapper for integrating axios to Vuejs
WhyI created this library because, in the past, I needed a simple solution to migrate from vue-resource to axios.
It only binds axios to the vue instance so you dont have to import everytime you use axios.
Support matrix VueJS VueAxios 1.x 2.x 3.x 1.x ✔ ✔ ✔ 2.x ✔ ✔ ✔ 3.x ❌ ❌ ✔ How to install: ES6 Module: npm install --save axios vue-axiosImport libraries in entry file:
// import Vue from vue // in Vue 2 import * as Vue from vue // in Vue 3 import axios from axios import VueAxios from vue-axiosUsage in Vue 2:
Usage in Vue 3:
const app = Vue.createApp(...) app.use(VueAxios, axios) Script:Just add 3 scripts in order: vue, axios and vue-axios to your document.
Usage: in Vue 2This wrapper bind axios to Vue or this if youre using single file component.
You can use axios like this:
Vue.axios.get(api).then((response) => { console.log(response.data) })...