【问题标题】:Why does vuex not fill my v-data-table?为什么 vuex 没有填满我的 v-data-table?
【发布时间】:2018-02-26 22:38:13
【问题描述】:

我有一个包含验证数据表的组件。这是连接到我的 vuex 存储,在加载组件时,它应该用数据填充表格。

加载后,我可以看到数据被提取并进入存储正常,但表没有更新。任何想法我做错了什么?

表格组件:

<template>
  <v-data-table :items="listOfUsers" hide-actions class="elevation-1">
    <template slot="items" slot-scope="props">
      <td>{{ props.item.userid }}</td>
      <td>{{ props.item.firstname }}</td>
      <td>{{ props.item.lastname }}</td>
      <td >{{ props.item.mobilenumber }}</td>
    </template>
  </v-data-table>
</template>

<script>

export default {
  name: 'usertable',
  computed: {
    listOfUsers () {
      return this.$store.state.users.userLIst
      }
    }
  }
  </script>

调用页面:

<template>
    <UserTable></UserTable>
</template>

<script>
import { FETCH_USER_LIST } from '../store/actions.type'

import UserTable from './UserTable.vue'
export default {
  name: 'Users',
  components: {
    UserTable
  },
  mounted: function () {
    this.$store.dispatch(FETCH_USER_LIST)
  }
}
</script>

不知道我做错了什么,因为我可以看到数据,但是表格没有更新。

商店在索引中的 registerid 如下所示:

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    auth,
    users
  }
})

【问题讨论】:

  • 你在根组件中注册了store吗? return this.$store.state.users.userLIst 真的正确吗? userLIst(大写I)?
  • 您好,更新了注册码问题。我像这样添加这些。我也可以看到 store 中的数据,只是没有更新到模型绑定。
  • userLIst中的大写I怎么样?不是笔误?另外,您没有任何其他根组件吗? new Vue({ ... } 一个?
  • 当我更改为更正拼写“userList”时,我在控制台中遇到了大量错误并发现了错误。我将商店设置为对象而不是数组。已修复,感谢您的帮助!
  • 哇,很高兴知道!

标签: vue.js vuejs2 vuex


【解决方案1】:

问题是数据表需要一个数组但得到一个对象。没有登录控制台,因为我错过了一个大写字母。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-28
    • 2021-04-23
    • 2020-01-25
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    相关资源
    最近更新 更多