1、命令行安装
npm install axios
2、在 main.js 中引入
import axios from 'axios'
3、在 main.js 中将 axios 改写为 vue 的原型属性 $http ,之后可在每个组件的 methods 中调用
Vue.prototype.$http=axios
4、在组件中使用
methods: {
get(){
this.$http({
method:'get',
url:'/url',
data:{}
}).then(function(res){
console.log(res)
}).catch(function(err){
console.log(err)
})
this.$http.get('/url').then(function(res){
console.log(res)
}).catch(function(err){
console.log(err)
})
}
}