vue-axios|axios中文网

本站由axios爱好者共建,部署在vultr vps上,推荐使用vultr!价格实惠,实力雄厚。 最近新注册用户充值$25,可额外获赠$50,搭建博客必备。 前往注册

vue-axios

基于vuejs 的轻度封装
npm version
install size
npm downloads

code helpers

安装:

CommonJS:

npm install --save axios vue-axios

将下面代码加入入口文件:

import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)

Script:

按照这个顺序分别引入这三个文件: vue, axios and vue-axios

Usage:

This wrapper bind axios to Vue or this if you’re using single file component.

你可以按照以下方式使用:

Vue.axios.get(api).then((response) => {
console.log(response.data)
})

this.axios.get(api).then((response) => {
console.log(response.data)
})

this.$http.get(api).then((response) => {
console.log(response.data)
})