Types of Vuex using getters

Asked

Viewed 89 times

1

import * as types from './types'
export default {

    // -=-=-==- OK -=-=-=-== //
    //return first item
    first(state, getters){
        return getters.list[0];
    },

    //retorn all itens from my api
    list: state => {
        return state.list
    },


    // -=-=-==- ERROR -=-=-=-== //

    //return first item 
    [types.FIRST](state, getters){
        //how change .all for types.all
        //return getters.[types.ALL][0] this exemple is worng
        return getters.all[0];

    },
    //retorn all itens
    [types.ALL]: state => {
        return state.list
    }

}

How do I use [type.ALL] inside another getter as in the example above, without the types I can access one getter inside another easily, but since I need to use the types I couldn’t find a way to call the getter all inside the list using [type.ALL]

  • Is this file just getters? shouldn’t these functions be inside a 'getters' object? and try the following where it’s going wrong: return getters[type.ALL]()[0], if it works I put an answer explaining.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.