2017-04-27 137 views
1

感謝您閱讀我的問題。無法讀取屬性'後'的undefined vue

我看了一下我的問題

VUE JS 2 + WEBPACK Cannot read property 'get' of undefined VUE RESOURCE

但是我的系統中沒有讀Vue的變種:(

我有一個VUE組件調用app.vue,我需要使用VUE資源以從我的後得到的數據,但錯誤很多次是:?

TypeError: Cannot read property 'post' of undefined 
at VueComponent.loadingProcess 

不要ü有想法解決它

我app.vue

<script> 
    var Vue = require('vue'); 
    //Vue.use(require('vue-resource')); 
    //Vue.use(); 

    export default { 
      data() { 
       return { 
        msg: 'Hello from vue-loader! nice!', 
        user: {} 
      } 
    }, 
    mounted: function() { 
     this.loadingProcess(); 
    }, 
    methods: { 
     loadingProcess: function() { 

      var urlPost; 
      var answQSend = {...}; 
      var that = this; 

      var jsonSend = { 
       "form_data": answQSend, 
       "prod_id": 3 
      }; 

      Vue.$http.post(urlPost, jsonSend, { 
       "headers": { 
        "content-type": "application/json" 
       } 
      }) 
      .then(function(response) { 

      }) 
      ... 

提前感謝!

回答

5

首先,感謝@Bert誰是耐心幫我找到解決

在我main.js,我改變了這一行

var VueResource = require('vue-resource'); 

import VueResource from "vue-resource" 

並使用

Vue.use(VueResource); 

然後,在我的應用程序VUE成分,我改變

Vue.http.post 

對於

this.$http.post 

這樣,我們固定的錯誤!