1/ namespace가 없는 모듈의 getters
namespace가 없는 모듈에서 getter를 가져올 때는, 아래와 같이 배열을 이용하여 가져올 수 있다.
import { mapGetters } from 'vuex';
export default {
computed: {
...mapGetters(['someGetter', 'anotehrGetter']),
},
}
2/ 하나의 namespace의 모듈의 getters
하나의 namespace의 모듈에서 getter를 가져올 때는, 첫번째 인수에 네임스페이스 이름 작성, 두번째 인수에는 배열에 가져올 getter를 작성하면 된다.
import { mapGetters } from 'vuex';
export default {
computed: {
...mapGetters('moduleName', ['someGetter', 'anotherGetter'])
}
}
Q. 그렇다면 여러 namespace의 모듈에서 getters를 가져올 때는 어떻게 해야할까?
1) 아래와 같이 mapGetters를 namespace별로 나눠서 여러개 작성해도 되고,
import { mapGetters } from 'vuex';
export default {
computed: {
...mapGetters('moduleName', ['someGetter', 'anotherGetter']),
...mapGetters('moduleName2', ['newSomeGetter', 'newAnotherGetter'])
}
}
2) 아래와 같이 객체를 이용해서 한 mapGetters 안에 '네임스페이스 명/가지고 올 getter명' 이렇게 작성해도 된다.
import { mapGetters } from 'vuex';
export default {
computed: {
...mapGetters({
someGetter: 'moduleName/someGetter',
anotherGetter: 'moduleName/anotherGetter',
newSomeGetter: 'moduleName2/newSomeGetter',
newAnotherGetter: : 'moduleName2/newAnotherGetter'
})
}
}
https://merrily-code.tistory.com/238
'Vue.js' 카테고리의 다른 글
[Udemy Vue 완벽가이드 Section15] 225. Vuex 코드 및 파일 구조화하기 (0) | 2023.11.12 |
---|---|
[Udemy Vue 완벽가이드 Section15] 224. 네임스페이스 모듈 (2) | 2023.11.08 |
[Udemy Vue 완벽가이드 Section15] 223. 지역 모듈 상태 이해하기 (0) | 2023.11.07 |
vue-cli로 vue프로젝트 생성 시, main.js와 index.html파일은 어떻게 연결될까? (0) | 2023.11.07 |
[Udemy Vue 완벽가이드 Section15] 222. 모듈로 저장소 구성하기 (0) | 2023.10.25 |