반응형
vuex: 알 수 없는 getter: 기사
구현하려고 합니다.vuex
모듈 및 사용법에 대해 설명합니다.내 모듈 Import 시도 중home.vue
다음과 같은 해결책을 찾았습니다.
import { FETCH_INDEX_ARTICLES } from "@/store/types/actions.type.js";
// imports this => export const FETCH_INDEX_ARTICLES = "fetchIndexArticles"
import { mapGetters, mapActions} from 'vuex'
export default {
name: "Home",
data() {
return {}
},
computed: {
...mapGetters(['articles']),
},
methods: {
...mapActions([FETCH_INDEX_ARTICLES])
}
created() {
this.$store.dispatch(FETCH_INDEX_ARTICLES);
}
};
하지만 대신 나는
vuex.esm.js?2f62:438 [vuex] unknown action type: fetchIndexArticles
vuex.esm.js?2f62:950 [vuex] unknown getter: articles
store/index.displaces
export default new Vuex.Store({
modules: {
articles,
}
});
store/module/module.module.models
const state = {
articles: [],
};
const getters = {
articles(state) {
return state.articles;
},
};
const mutations = {
[SET_ARTICLES] (state, pArticles) {
state.article = pArticles
state.errors = {}
}
}
const actions = {
[FETCH_INDEX_ARTICLES] (context) {
context.commit(FETCH_START)
return ApiService
.get('/articlelist/index/')
.then((data) => {
context.commit(SET_ARTICLES, data.articles);
context.commit(FETCH_END)
})
.catch((response) => {
context.commit(SET_ERROR, response.data.errors);
})
}
};
export default {
namespaced: true,
state,
getters,
actions,
mutations
}
vuex 모듈을 올바르게 Import하려면 어떻게 해야 합니까?
고마워요.
모듈을 지정해야 합니다. 모듈을 컴포넌트로 직접 Import할 때 방법이 유효합니다.
...mapGetters('articles', {
article: 'articles',
})
this.article(2)
https://vuex.vuejs.org/guide/modules.html#binding-helpers-with-namespace
사용을 용이하게 하기 위해 나는 그 방법을 사용한다.dispatch
액션을 위해서
this.$store.dispatch('articles/FETCH_INDEX_ARTICLES', {anydata})
언급URL : https://stackoverflow.com/questions/61732170/vuex-unknown-getter-articles
반응형
'IT이야기' 카테고리의 다른 글
Vuex 및 라우터를 사용한vue 3 서버 측 렌더링 (0) | 2022.07.12 |
---|---|
플레인 VueJS 프로젝트에서 Typescript 함수 사용 (0) | 2022.07.12 |
Java List.contains(필드 값이 x와 동일한 개체) (0) | 2022.07.12 |
.c 및 .h 파일 확장자는 C에게 어떤 의미입니까? (0) | 2022.07.12 |
부울 필드의 경우 getter/setter 명명 규칙은 무엇입니까? (0) | 2022.07.12 |