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...

 

posted on 2017-11-30 17:38  南风知意  阅读(125)  评论(0)    收藏  举报

导航