配置:main.js
// axios
import axios from 'axios';
// axios方法绑定到全局
Vue.prototype.$http = axios;
用法:
export default {
data () {
return {
data:[],
}
},
created () {
this.getData()
},
methods: {
getData : function (){
this.$http.get('http://127.0.0.1').then(response => {
this.data = response.data;
}).catch(function (error) {
console.log(error);
});
}
}
}