【问题标题】:How can I use my getter for a computed property?如何将我的 getter 用于计算属性?
【发布时间】:2019-09-10 11:24:03
【问题描述】:

我有一个使用 Vuex 模块装饰器的简单 Vuex 商店

@Module
export default class WorkoutModule extends VuexModule {

    _workout: Workout;

    @Mutation
    startWorkout(workout) {
        this._workout = workout;
    }

    get workout() { return Workout; }

}

如何将我的 getter 用于计算属性?我试过这个:

computed: {
  ...mapGetters(['workout'])
},

但这不起作用。

【问题讨论】:

    标签: typescript vue.js vuex


    【解决方案1】:

    您需要设置命名空间。例如,在 vuex-class 中你会像这样输入 smth const foo = namespace('foo')

    【讨论】:

    • 谢谢,我不确定我必须在哪里设置命名空间,你知道有关这方面的任何文档吗?
    • 看看this。你应该在组件中指向你的命名空间,但在你应该给你的 vuex 模块命名之前。如果您对此有疑问,官方文档应该会有所帮助。
    猜你喜欢
    • 2018-07-22
    • 2020-01-07
    • 2017-09-29
    • 2019-09-12
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 2017-11-30
    相关资源
    最近更新 更多