您正尝试从vue组件修改vuex状态,但您无法执行此操作.您只能从变异中修改vuex存储
您可以定义如下的突变:
var store = new Vuex.Store({ state: { customers: [ { id: '1', name: 'user 1',}, ] }, mutations: { addCustomer (state, customer) { // mutate state state.customers.push(customer) } } })
现在您可以从vue实例提交此突变,如下所示:
mounted: function() { this.$http.get('http://localhost/facebook-login/api/get_customers.php') .then(response => { return response.data; }) .then(data => { store.commit('addCustomer', { id: '2', name: 'User 2'}) }); }