반응형
vuex를 사용하여 이름 지정 모듈에서 getter에 액세스하려면 어떻게 해야 합니까?
모듈에는 다음이 있습니다.
export default {
namespaced: true,
state: {
conversations: false
},
getters: {
getConversation(state, ConversationId) {
console.log('here i am!')
let conversation = _.find(state.conversations, { id: ConversationId })
console.log('conversation', conversation)
return conversation
},
내 컴포넌트에서는 다음을 시도하고 있습니다.
export default {
name: "ConversationDetail",
components: { HeaderSection },
computed: {
...mapGetters("conversation", ["getConversation"]),
ConversationId() {
return this.$route.params.ConversationId;
},
conversation() {
return this.getConversation(this.ConversationId);
}
},
methods: {
...mapActions("conversation", ["loadConversation"])
},
mounted() {
this.loadConversation(this.ConversationId);
하지만 오류가 발생합니다.
Error in render: "TypeError: this.getConversation is not a function"
내가 뭘 잘못하고 있지?
getter를 올바르게 참조하고 있지만, 파라미터를 getter에 전달하려면 예를 들어 cured lambda와 같이 파라미터를 사용하는 함수를 반환해야 합니다.
getter: (state) => (ConversationId) => {...}
언급URL : https://stackoverflow.com/questions/57563468/how-can-i-access-a-getter-from-a-namespaced-module-with-vuex
반응형
'sourcecode' 카테고리의 다른 글
사용되지 않는 함수 매개 변수 값을 void로 캐스팅하는 이유는 무엇입니까? (0) | 2022.08.03 |
---|---|
C의 구조 크기 (0) | 2022.08.03 |
이 네 줄의 까다로운 C 코드 뒤에 있는 개념 (0) | 2022.08.03 |
Vuex getter(인수가 Typescript에 기록됨) (0) | 2022.08.03 |
vue2-datepicker에서 시간대를 설정하는 방법 (0) | 2022.08.03 |