【问题标题】:Vuex mapActions, mapGetters, etc... Mixing namespaced and non-namespace actions/getters/mutations/state in the same call?Vuex mapActions、mapGetters 等...在同一个调用中混合命名空间和非命名空间操作/getters/mutations/state?
【发布时间】:2019-06-06 17:37:27
【问题描述】:

我只是好奇是否有一种方法可以在您调用 ...mapActions 时混合使用命名空间和非命名空间的操作。我只有一个足够大的模块来保证完整的模块封装和命名空间,所以有些动作是things/someAction,有些只是someOtherAction。我目前正在像这样映射:

...mapActions('nsACtions', ['nsOne', 'nsTwo']),
...mapActions('nonNsActionOne', 'nonNsActionTwo')

但更愿意将所有内容合并为一个mapActions。比如:

...mapActions('nsACtions', 
    ['nsOne', 'nsTwo'],
    'nonNsActionOne', 
    'nonNsActionTwo')

...mapActions('nsACtions', 
    ['nsOne', 'nsTwo'],
    ['nonNsActionOne', 
    'nonNsActionTwo'])

这些例子都不起作用,所以我很好奇是否有人解决了这个小难题。谢谢!

【问题讨论】:

    标签: vue.js vuejs2 vue-component vuex vuetify.js


    【解决方案1】:

    我已经添加了这个答案,尽管 Matt Larson 发现自己的解决方案在很大程度上反映了同样的事情。您可以在计算值上使用多个 mapAction 来分隔命名空间,以便更清晰

    computed: {
         mapActions('namespace', ['nsOne','nsTwo']),
         mapActions(['nonNsOne','nonNsTwo']),
    }
    

    【讨论】:

      【解决方案2】:

      没关系。想出来是这样的:

      ...mapActions({
        nsOne: 'namespaced/nsOne',
        nsTwo: 'namespace/nsTwo',
        nonNsOne: 'nonNsOne', 
        nonNsTwo: 'nonNsTwo'
      })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-27
        • 2011-11-26
        • 2021-05-17
        • 2020-07-14
        • 2020-03-29
        • 2021-03-16
        • 2021-11-17
        • 2019-01-21
        相关资源
        最近更新 更多