1 | # vue-axios
|
2 | A small wrapper for integrating axios to Vuejs
|
3 |
|
4 | ## How to install:
|
5 | ### CommonJS:
|
6 | ```bash
|
7 | npm install --save axios vue-axios
|
8 | ```
|
9 |
|
10 | And in your entry file:
|
11 | ```js
|
12 | import Vue from 'vue'
|
13 | import axios from 'axios'
|
14 | import VueAxios from 'vue-axios'
|
15 |
|
16 | Vue.use(VueAxios, axios)
|
17 | ```
|
18 |
|
19 | ### Script:
|
20 | Just add 3 scripts in order: `vue`, `axios` and `vue-axios` to your `document`.
|
21 |
|
22 | ## Usage:
|
23 | This wrapper bind `axios` to `Vue` or `this` if you're using single file component.
|
24 |
|
25 | You can `axios` like this:
|
26 | ```js
|
27 | Vue.axios.get(api).then((response) => {
|
28 | console.log(response.data)
|
29 | })
|
30 |
|
31 | this.axios.get(api).then((response) => {
|
32 | console.log(response.data)
|
33 | })
|
34 |
|
35 | this.$http.get(api).then((response) => {
|
36 | console.log(response.data)
|
37 | })
|
38 | ```
|