我目前有一个对象的数组,我正在渲染到一个表。我试图按照Vuejs提供的例子使用同一页面上多个vues之间共享的“单一真相源”。总之,我试图让vue1.refresh()被触发时,所有的vues更新他们的数据,当“单一真相源”被更新时。然而,self.surveys =调查;只更新vue1上的数据。VueJS:替换/更新阵列
注:我下面从https://vuejs.org/v2/guide/state-management.html
// The single source of truth
var cache = {
data: [{...}] // Array of objects
}
var vue1 = new Vue({
el: "#table",
data: {
surveys: cache.data // Points to the single source of truth
},
methods: {
refresh: function(){
var self = this;
// After getting data back from an ajax call
.done(function(surveys) {
self.surveys = surveys;
});
},
}
});
var vue2 = new Vue({
el: "#table",
data: {
surveys: cache.data // Points to the single source of truth
},
methods: {
// Methods
}
});
看一看[Vuex](https://vuex.vuejs.org/) – Vanojx1
你不应该改变另一个组件的数据,比如来自一个孩子的父母的数据。 –