我的模块有:
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
},
Run Code Online (Sandbox Code Playgroud)
在我的组件中,我正在尝试:
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);
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:
Error in render: "TypeError: this.getConversation is not a function"
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
您正确地引用了 getter,但是,如果您希望将参数传递给 getter,则需要返回一个接受您的参数的函数,例如使用柯里化 lambda:
getter: (state) => (ConversationId) => {...}
| 归档时间: |
|
| 查看次数: |
221 次 |
| 最近记录: |