gpt4 book ai didi

javascript - Vue动态 map Getters

转载 作者:搜寻专家 更新时间:2023-10-30 22:20:33 24 4
gpt4 key购买 nike

我有一个 Prop ,我想用它来制作一个动态的 mapGetters,但是 mapGetters 认为 Prop 是未定义的,可能是因为计算是在 Prop 之前加载的。有人知道我怎样才能让它变得动态吗?我的代码如下:

export default {
props: ['listType'],
components: {
addrow: AddRow
},
computed: {
...mapGetters({
list: `${this.listType}/list`,
current: 'Dropdown/current'
})
},
}

最佳答案

[更新]感谢@boussadjrabrahim,我找到了解决方案我的工作代码如下所示:

export default {
props: ['listType'],
components: {
addrow: AddRow
},
computed: {
...mapGetters({
current: 'Dropdown/current'
}),

...mapState({
list (state, getters) {
return getters[`${this.listType}/list`]
}
})
}
}

关于javascript - Vue动态 map Getters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52577895/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com