sourcecode

vuex를 사용하여 이름 지정 모듈에서 getter에 액세스하려면 어떻게 해야 합니까?

copyscript 2022. 8. 3. 23:08
반응형

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

반응형