2017-09-03 41 views
0

我試圖獲取使用Vue公司+ Vuex + Vue公司resource.On按鈕服務器數據單擊我想打HTTP請求並顯示在列表格式。我試圖像that.Here是我的代碼如何從vue js中的服務器獲取數據?

https://plnkr.co/edit/EAaEekLtoiGPvxkmAtrt?p=preview

// Code goes here 

var store = new Vuex.Store({ 
    state: { 
     Item: [] 
    }, 
    mutations: { 
     getItems: function (state) { 

     } 

    }, 
    actions: { 
     fetchData:function (context) { 
      this.$http.get('/data.json', function(v1users) 
       { 
        // this.$set('v1_user',v1users); 
      }); 
     } 
    } 
}) 

var httprequest = Vue.extend({ 
    "template": '#http_template', 
    data: function() { 
     return { 
      items: store.state.Item 
     } 
    }, 
    methods: { 
     fetchData: function() { 
      store.dispatch('fetchData') 
     }, 

    } 
}) 

Vue.component('httprequest', httprequest); 

var app = new Vue({ 
    el: '#App', 
    data: {}, 


}) 

; 任何udpdate?

回答

0

嘗試使用Vue.http.get代替this.$http.get

Vuex不必$http直接從實例的訪問。

+0

請你分享plunker – naveen

+0

我怎麼會做呢? – naveen

+0

無需plunker ..只要請'Vue.http.get'在你的代碼替換'這一點。$ http.get'。這是你需要做的唯一改變。 – mariodev