Introduction to the

The original intention of vue plugin (vUE – AXIos3) is to introduce AXIos plugin into Vue more semantically, so that it is easier and faster to develop.

Compatible with

Vue \ vAxios 1.x 2.x 3.x
2.x
3.x

advice

Version 3.0 supports VUe2 and VUE3

Install && import

  • npm
npm install v-axios --save
Copy the code
import vAxios from 'v-axios';
// Not importing this will automatically inject axios
import axios from 'axios';
Copy the code

Using the Vue 2:

The second parameter is optional
Vue.use(VueAxios[, axios]);
Copy the code

Using the Vue 3:

import { createApp } from 'vue';

constapp = createApp(...) ;The second parameter is optional
app.use(vAxios[, axios]);
Copy the code
  • Directly introducing
<script src="https://unpkg.com/axios"></script>
<script src="https://unpkg.com/v-axios"></script>
Copy the code

use

Either app.axios or this.$HTTP can be called

You should use it as follows:

// get
/ / es6 writing
Vue.axios.get('xxx').then(res= > console.log(res.data));

/ / es5 writing
Vue.axios.get('xxx', {
  params: {... } }).then(function (res) {
  console.log(res);
}).catch(function (err) {
  console.log(err);
});

// post
/ / es6 writing
this.$http.post('xxx').then(res= > console.log(res.data)).catch(err= > console.log(err)});

/ / es5 writing
this.$http.post('xxx', {... }).then(function (res) {
  console.log(res);
}).catch(function (err) {
  console.log(err);
});
Copy the code

API

See the -axios API

If you feel good, give a star. Thank you