我有一个props ,我想用它来制作一个动态的mapGetters,但是mapGetters认为这些props 是未定义的,可能是因为计算结果是在props 之前加载的.有人知道我怎样才能让它充满活力吗?我的代码如下:

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

推荐答案

[更新]

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

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

Vue.js相关问答推荐

Vue ChildComponent (GrandchildComponent) 应该更新 ParentComponent 的列表

VSelect - Select 不适用于 Vuetify 3 中的自定义项目插槽

通过元素加中的正则表达式输入电话号码格式

Nuxt 和 Vite 有什么区别?

如果单元格不可见,则以编程方式打开行的编辑模式. Ag 网格,Vue.js

如果在 VueJS/VuetifyJS 中切换switch,则调用函数

从数据库中删除后,Vue.js $remove 不删除元素

在 jest document.querySelector 中测试 vue 组件期间始终返回 null

Vue:如何将 store 与组件一起使用?

如何只查看数组中的一个对象?

在 v-for 的情况下如何从 v-model 输入更新 Vuex 存储

如何在 vue 3 脚本设置中的组件上使用 v-model

错误 [ERR_UNSUPPORTED_ESM_URL_SCHEME]:默认 ESM 加载器仅支持文件和数据 URL - Vue 3

在组件外使用 VueI18n 的问题

如何使用 TypeScript 在 Vue.js 中指定非react性实例属性?

Jest错误找不到模块....

我在 Nuxt 2.14.0 中运行的是什么版本的 Vue?

如何从组件内的单点捕获 vuejs 错误

Vue 2.0 设置路由 - 不要使用new来产生副作用

使用 CloudFront 部署在 S3 上的 VueJS 应用程序的指定的密钥不存在