1 | # vue-axios
|
2 | A small wrapper for integrating axios to Vuejs
|
3 |
|
4 | ## Support matrix
|
5 |
|
6 | |VueJS \ VueAxios|1.x|2.x|3.x|
|
7 | |-|-|-|-|
|
8 | |1.x|✔|✔|✔|
|
9 | |2.x|✔|✔|✔|
|
10 | |3.x|❌|❌|✔|
|
11 |
|
12 | ## How to install:
|
13 | ### ES6 Module:
|
14 | ```bash
|
15 | npm install --save axios vue-axios
|
16 | ```
|
17 | Import libraries in entry file:
|
18 | ```js
|
19 | import Vue from 'vue'
|
20 | import axios from 'axios'
|
21 | import VueAxios from 'vue-axios'
|
22 | ```
|
23 |
|
24 | Usage in Vue 2:
|
25 | ```js
|
26 | Vue.use(VueAxios, axios)
|
27 | ```
|
28 |
|
29 | Usage in Vue 3:
|
30 | ```js
|
31 | const app = Vue.createApp(...)
|
32 | app.use(VueAxios, axios)
|
33 | ```
|
34 |
|
35 | ### Script:
|
36 | Just add 3 scripts in order: `vue`, `axios` and `vue-axios` to your `document`.
|
37 |
|
38 | ## Usage:
|
39 | This wrapper bind `axios` to `Vue` or `this` if you're using single file component.
|
40 |
|
41 | You can use `axios` like this:
|
42 | ```js
|
43 | Vue.axios.get(api).then((response) => {
|
44 | console.log(response.data)
|
45 | })
|
46 |
|
47 | this.axios.get(api).then((response) => {
|
48 | console.log(response.data)
|
49 | })
|
50 |
|
51 | this.$http.get(api).then((response) => {
|
52 | console.log(response.data)
|
53 | })
|
54 | ```
|
55 |
|
56 | Please kindly check full documention of [axios](https://github.com/axios/axios) too
|