【问题标题】:Use props in computed and methods while mounting安装时在计算和方法中使用道具
【发布时间】:2020-07-10 10:23:56
【问题描述】:

我正在尝试将 vuex/mapGetters 和 mapActions 与这样的道具一起使用。 但是在执行此代码时未定义道具。我怎样才能做到这一点?

  methods: {
    ...mapActions(`orders/${this.unitStatus}`, {
      getOrders: 'getOrders'
      ...
    }),
    ...OtherMethods...

  computed: {
    ...mapGetters(`orders/${this.unitStatus}`, {
      isLoading: 'isLoading',
      orderUnits: 'orderUnits',
      ...

【问题讨论】:

  • 你能从商店添加getter或action代码吗?
  • 这有什么帮助? getter 只是返回状态,动作运行一些 gql 代码。

标签: vue.js vuejs2 vuex


【解决方案1】:

我找到了我要找的东西。 Vue dynamic mapGetters

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

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

【讨论】:

    猜你喜欢
    • 2021-05-09
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 2021-03-04
    • 2023-02-17
    • 2019-03-01
    • 2019-03-31
    • 2022-01-22
    相关资源
    最近更新 更多