반응형
[Vue.js] Vuex에서의 네임스페이스
모듈의 getter, metations, actions의 네임 스페이스를 설정하려고 합니다.이 문서는 여기서 볼 수 있습니다만, 조금 애매한 것 같습니다.
// types.js
// define names of getters, actions and mutations as constants
// and they are prefixed by the module name `todos`
export const DONE_COUNT = 'todos/DONE_COUNT'
export const FETCH_ALL = 'todos/FETCH_ALL'
export const TOGGLE_DONE = 'todos/TOGGLE_DONE'
// modules/todos.js
import * as types from '../types'
// define getters, actions and mutations using prefixed names
const todosModule = {
state: { todos: [] },
getters: {
[types.DONE_COUNT] (state) {
// ...
}
},
actions: {
[types.FETCH_ALL] (context, payload) {
// ...
}
},
mutations: {
[types.TOGGLE_DONE] (state, payload) {
// ...
}
}
}
다음으로 vue 컴포넌트에서 모듈화된 getters, mutation을 사용하려면 어떻게 해야 합니까?
export default {
data() {
// like this?
count: this.$store.getters.DONE_COUNT,
// ?
count: this.$store.getters.todos.DONE_COUNT,
// ?
count: this.$store.getters.todosModule.DONE_COUNT,
// ?
count: ?,
},
};
this.$store.getters['todos/DONE_COUNT']
언급URL : https://stackoverflow.com/questions/40549997/vue-jsnamespacing-in-vuex
반응형
'programing' 카테고리의 다른 글
알려진 리소스 이름을 가진 리소스 ID를 가져오려면 어떻게 해야 합니까? (0) | 2022.06.04 |
---|---|
난독화 C코드 콘테스트 2006.sykes 2.c에 대해 설명해 주세요. (0) | 2022.06.04 |
C에서 _start()의 용도는 무엇입니까? (0) | 2022.06.04 |
Vue js - 특정 유형으로 프로펠러 정의 (0) | 2022.06.04 |
vue.js의 하위 컴포넌트에 전달된 소품의 로컬 복사본을 작성하시겠습니까? (0) | 2022.06.04 |