1、安装
npm install --save axios vue-axios
或 cnpm install --save axios vue-axios
2、在主文件 main.js 引入
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)
3、在组件里使用
(1)推荐
this.axios.get(api).then((response) => {
console.log(response)
})
(2)
import Vue from 'vue' //需要引入vue
Vue.axios.get(api).then((response) => {
console.log(response.data)
})
(3)
this.$http.get(api).then((response) => {
console.log(response)
})
网友评论