嘿,我正在Vue上工作,Vuex
使用装饰器强类型化模板项目。
由于我是整个商店的新手,所以我无法理解如何正确配置商店以按预期在组件中工作。
我最终要实现的是调用不同商店模块的操作,如下:
this.$store.nameOfMyModule.NameOfAction
this.$store.<nameOfMyModule.NameOfGetter
该项目的一个更具体的例子是
this.$store.tickets.tickets
this.$store.tickets.fetchTickets
这里是repo的链接
我认为最好使用mapActions
和mapGetters
:
import { mapActions, mapGetters } from 'vuex'
//...
computed: {
...mapGetters('tickets', [
tickets
]),
...mapGetters('users', [
users
])
},
methods : {
...mapActions('tickets', [
fetchTickets
]),
...mapActions('users', [
fetchUsers
])
}
//...
之后,您可以直接在组件this.fetchTickets()
和this.tickets
中使用
最后,必须将fetchUsers
置于活动的users
模块中,而不是fetchTickets