npm i -S axios vue-axios
将下面代码加入入口文件:
import Vue from ‘vue‘
import axios from ‘axios‘
import VueAxios from ‘vue-axios‘
Vue.use(VueAxios, axios)
你可以按照以下方式使用:
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)
})
this.$http.get(‘url‘, {
params: {}
})
this.$http.post((‘url‘, {}))
原文:https://www.cnblogs.com/diygou/p/15064956.html