【发布时间】:2018-12-21 16:41:24
【问题描述】:
我有一个看起来像这样的 Vue 文件:
import store from '@/store'
export default{
name: 'myList',
data: () => ({
show: true,
listContent: [{
name: '1',
icon: 'person',
value: function () {
return store.state.myStore.settings.one
}
}, {
name: '2',
icon: 'person',
value: function () {
return store.state.myStore.settings.two
}
}, {
name: '3',
icon: 'person',
value: function () {
return store.state.myStore.settings.three
}
}
]
})
}
不起作用的部分是从“listContent”中获取“值”。
{
name: '3',
icon: 'person',
value: function () {
return store.state.myStore.settings.three
}
}
在我的代码中,我已经导入了视图,就好像我要放置:
this.$store.state.myStore.settings.one
在值函数内部,'this' 将引用对象
{
name: '3',
icon: 'person',
value: function () {
return store.state.myStore.settings.three
}
}
而且我无法获得商店。但是,我的代码仍然无法正常工作。我需要访问 listContent 中的商店。
列表呈现如下:
<v-data-table :items="listContent" hide-actions hide-headers>
<template slot="items" slot-scope="props">
<td>{{ props.item.name }}</td>
<td class="text-xs-right" v-text="props.item.value()"> </td>
</template>
</v-data-table>
要么我错误地引用了商店,要么模板不正确。有什么想法吗?
【问题讨论】:
-
商店包含模块,我想从中获取的模块是名称'myStore'
-
您希望这些值具有反应性吗?
标签: javascript vue.js vuex vuetify.js