Programing

mapGetters에서 단일 Vue getter 별칭

c10106 2022. 4. 22. 18:52
반응형

mapGetters에서 단일 Vue getter 별칭

나는 게터들이 있는 vuex 모듈을 가지고 있다.이 모듈의 게터를 vue 구성 요소에 사용하고 있다.

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

나는 다른 vuex 모듈들을 가지고 있다.isActive게터, 그래서 여기에 가명을 붙이고 싶어나는 객체 구문에 익숙하다.

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

하지만, 나는 가명을 쓸 필요가 없다.'someOtherGetter'또는'yetAnotherGetter', 그리고 객체 구문에서는 내가 단지 그것만을 해야 한다고 요구하는 것 같다.

getter 중 하나만 별칭으로 지정할 수 있도록 mapGetter와 함께 사용할 구문이 있는가?

두 번 사용하는 건 어때?

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

그리고 Vuex 모듈의 이름을 지정하는 것은 어떨까?따라서 이와 같은 이름의 충돌은 피할 것이다.

참조URL: https://stackoverflow.com/questions/62154946/alias-a-single-vue-getter-in-mapgetters

반응형