Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias a single Vue getter in mapGetters

Tags:

vue.js

vuex

I have a vuex module with getters. I am using this module's getters in a vue component:

...
computed: {
    ...mapGetters('myCoolModule', ['isActive', 'someOtherGetter', 'yetAnotherGetter']),
}
...

I have other vuex modules that have an isActive getter, so I would like to alias it here. I am familiar with the object syntax, i.e.,

...
computed: {
    ...mapGetters('myCoolModule', { myCoolModuleIsActive: 'isActive', someOtherGetter: 'someOtherGetter', yetAnotherGetter: 'yetAnotherGetter' }),
}
...

However, I do not need to alias 'someOtherGetter' or 'yetAnotherGetter', and the object syntax seems to require that I do just that.

Is there a syntax to use with mapGetters such that I can alias only one of the getters?

like image 997
Avocado Avatar asked Sep 19 '25 17:09

Avocado


1 Answers

What about using it twice ?

computed:
{
  ...mapGetters('myModule', {
    myCoolModuleIsActive: 'isActive',
  }),
  ...mapGetters('myModule', ['someOtherGetter', 'yetAnotherGetter']),
}

And why not namespacing your Vuex modules ? Thus name collisions like this will be avoided.

like image 64
IVO GELOV Avatar answered Sep 22 '25 06:09

IVO GELOV