【发布时间】: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”时,我在控制台中遇到了大量错误并发现了错误。我将商店设置为对象而不是数组。已修复,感谢您的帮助!
-
哇,很高兴知道!