我有很多 getter 将参数传递给商店,例如:
this.$store.getters['getSomeThing'](this.id)
我没有找到有关如何最佳使用的建议mapGetters
保持反应性,同时传递参数。我发现的一个建议是映射 getter,然后在 Mounted 中传递参数:
computed: {
...mapGetters([
'getSomeThing'
])
},
mounted () {
this.getSomeThing(this.id)
}
这似乎确实不是最优的,因为它只会检查已安装状态的更改。关于如何在将参数传递给吸气剂时最好地保持反应性,有什么建议吗?下面是与上述代码匹配的 getter 示例:
getSomeThing: (state) => (id) => {
return state.things.find(t => { return t.id === id })
}
这是我的一个项目的片段:
computed: {
...mapGetters('crm', ['accountWithId']),
account() {
return this.accountWithId(this.$route.params.id)
}
},
这使得this.account
反应性且依赖于参数。
So...
computed: {
...mapGetters([
'getSomeThing'
]),
thing() {
return this.getSomeThing(this.id)
}
},
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)