如何將數據發送到Vue.js中的組件?我在按鈕點擊事件中得到了服務器的響應,現在我想將此響應發送到組件並使用v-for
在list
上顯示。如何向vue js中的組件發送數據?
這裏是我的代碼:
var store = new Vuex.Store({
state: {
Item: []
},
mutations: {
getItems: function (state) {
}
},
actions: {
fetchData:function (context) {
Vue.http.get('data.json').then(function(response){
alert('dd')
}, function(error){
console.log(error.statusText);
});
}
}
})
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: {},
});
[如何在VUE js中的組件之間共享數據(當創建列表時)](https://stackoverflow.com/questions/46015442/how-to-share-data-between-components-in-vue -js-while-creating-list) – bbsimonbb