推送到Vuex存储阵列在VueJS中不起作用

Vue.js

逆天TomHarry

2020-03-16

我正在使用Vuex来显示“ store.js”中的用户列表。该js文件具有这样的数组。

var store = new Vuex.Store({
  state: {
    customers: [
      { id: '1', name: 'user 1',},
    ]
  }
})

我想向同一数组插入一组新值

{id:“ 1”,名称:“ user 1”,}

以上值是从URL(资源资源)获得的。下面是将获得的数据推送到数组的代码。但是,数据未插入

mounted: function() {
      this.$http.get('http://localhost/facebook-login/api/get_customers.php')
      .then(response => {
        return response.data;
      })
      .then(data => {
        store.state.customers.push(data) // not working!!
        console.log(data) // prints { id: '2', name: 'User 2',}
        store.state.customers.push({ id: '2', name: 'User 2',})
      });
    }

第1731篇《推送到Vuex存储阵列在VueJS中不起作用》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android