Vuex反应式mapGetters与传递的参数

Mat*_*son 3 state flux vue.js vuex vuejs2

我有很多将参数传递给商店的吸气剂,例如:

this.$store.getters['getSomeThing'](this.id)
Run Code Online (Sandbox Code Playgroud)

我没有找到关于如何mapGetters在传递参数的同时如何最佳地使用来保持反应性的建议。我发现的一个建议是映射吸气剂,然后将参数传递给mount:

computed: {  
  ...mapGetters([
    'getSomeThing'
  ])
},
mounted () {
  this.getSomeThing(this.id)
}
Run Code Online (Sandbox Code Playgroud)

这实际上似乎不是最佳选择,因为它只会检查已挂载状态的更改。关于如何在将参数传递给吸气剂时如何最好地保持反应性的任何建议?这是与上述代码匹配的吸气剂的示例:

getSomeThing: (state) => (id) => {
  return state.things.find(t => { return t.id === id })
}
Run Code Online (Sandbox Code Playgroud)

Jef*_*eff 9

这是我有一个项目的片段:

    computed: {
        ...mapGetters('crm', ['accountWithId']),
        account() {
            return this.accountWithId(this.$route.params.id)
        }
    },
Run Code Online (Sandbox Code Playgroud)

这使得this.account反应性并取决于参数。

所以...

computed: {  
  ...mapGetters([
    'getSomeThing'
  ]),
  thing() {
    return this.getSomeThing(this.id)
  }
},
Run Code Online (Sandbox Code Playgroud)