我有一个基于Vue和Vuex的小应用程序。它只是一张桌子,里面有这样的东西
<div class='items'>
<div v-for='item in items'>
<span> {{ item.name }} </span>
<router-link :to='"update/" + item.id'>Edit</router-link>
</div>
</div>使用getter从Vuex状态加载Items数组。所以问题是,当我按下“编辑”按钮时,它会将我重定向到另一个页面,在那里我有一个类似的功能
computed() {
item() {
return this.$store.getters.get_item(this.$route.params.id)
}
}一般来说,它应该可以工作(我通过传递一些数字来测试它,而不是传递"this.$route.params.id"),但它不..为什么?没有错误,什么也没有,只有空数组
我的get_item函数
getters: {
get_item: (state) => (index) => {
return state.items.filter((item) => {
return item.id === index
}
}
}发布于 2017-11-25 18:58:55
您将computed定义为一个函数,而它应该是一个对象。相反,尝试:
computed: {
item() {
return this.$store.getters.get_item(this.$route.params.id)
}
}https://stackoverflow.com/questions/47455303
复制相似问题