Vue Axios的配置 (高仿饿了么)
export default { name: "app", components: { "v-header": header }, data() { return { seller: {} }; }, created() { let _this = this; // 让this始终代表最初this指向的对象 this.axios .get('../data.json') .then(function(res) { _this.seller = res.data.seller console.log(_this.seller) // } }) .catch(error => { console.log(error); }); } }; </script>
上代码生效的前提
import Vue from 'vue' import axios from 'axios' Vue.prototype.axios = axios // 也可以 Vue.prototype.$http = axios , this.axios... 就要改为 this.$http...
浙公网安备 33010602011771号