我有很多将参数传递给商店的吸气剂,例如:
this.$store.getters['getSomeThing'](this.id)
我没有找到有关如何在传递参数的同时最佳地使用mapGetters
来保持反应性的建议。我发现的一个建议是映射吸气剂,然后在mount中传递参数:
computed: {
...mapGetters([
'getSomeThing'
])
},
mounted () {
this.getSomeThing(this.id)
}
这似乎不是最佳选择,因为它只会检查已安装状态的更改。关于如何在将参数传递给吸气剂时如何最好地保持反应性的任何建议?这是与上述代码匹配的吸气剂的示例:
getSomeThing: (state) => (id) => {
return state.things.find(t => { return t.id === id })
}
答案 0 :(得分:5)
这是我有一个项目的摘录:
computed: {
...mapGetters('crm', ['accountWithId']),
account() {
return this.accountWithId(this.$route.params.id)
}
},
这使this.account
变得反应灵敏,并依赖于参数。
所以...
computed: {
...mapGetters([
'getSomeThing'
]),
thing() {
return this.getSomeThing(this.id)
}
},