B
B
BonBon Slick2019-09-30 16:12:08
JavaScript
BonBon Slick, 2019-09-30 16:12:08

Dynamic access in ...mapAction and ...mapGetter?

import { mapActions, mapGetters } from 'vuex';

    export default {
        name:     'posts_list',
        props:    {
            type: {
                type:     String,
                required: false,
                default:  'posts',
            },
        },
        computed: {
            ...mapGetters({
                list:                   `list/${this.type}`, // error, this = undefined

Throws
сannot read property 'type' of undefined
a Potmou error that this is not available. Methods are also not available there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nvdfxx, 2019-09-30
@BonBonSlick

computed {
    getList() {
        return this.$store.getters[`list/${this.type}`]
    }
}

although it might not work with modules

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question