vue-axios
一个用于将axios集成到Vuejs的小型包装器。
版本支持
| VueJS \ VueAxios | 1.x | 2.x | 3.x |
|---|---|---|---|
| 1.x | ✔ | ✔ | ✔ |
| 2.x | ✔ | ✔ | ✔ |
| 3.x | ❌ | ❌ | ✔ |
安装
npm
npm install --save axios vue-axios
在入口文件中导入库
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
在Vue 2中使用
Vue.use(VueAxios, axios)
在Vue 3中使用
const app = Vue.createApp(...)
app.use(VueAxios, axios)
提示
只需将3个scripts:vue、axios和vue-axios按顺序添加到文档中。
示例
你可以像这样使用axiox:
// 全局
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)
})
也请查阅axios的完整文档。
642

被折叠的 条评论
为什么被折叠?



