我定义了一个带有参数的vuex getter函数,代码如下:
const getters = {
getProjectById: (state) => (id) => {
return state.projects.find(project => project.id === id)
}
}
现在,我想在我的组件中使用这个getter函数,但是我找不到一种方法来将参数传递给getter。
这是我的getter hook计算属性:
computed: {
...mapGetters(["currentUserPhoto","getProjectById"])
},
有没有可能将来自路由的Id参数传递给“getProjectId”getter?如果可能的话,最好的方法是什么?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
添加另一个计算属性,名为
projectById,它接受路由参数作为参数,并返回项目:computed: { ...mapGetters(["currentUserPhoto","getProjectById"]), projectById(){ return this.getProjectById(this.$route.params.id) } },