vuejs2 - How do I call a getter from another getter in Vuex? -


consider simple vue blog. i'm using vuex datastore , need set 2 getters: getpost getter retrieving post id, listfeaturedposts returns first few characters of each featured post. datastore schema featured posts list references posts ids. these ids need resolved actual posts purposes of showing excerpts.

store/state.js

export const state = {   featuredposts: [2, 0],   posts: [     'lorem et ipsum dolor sit amet',     'lorem et ipsum dolor sit amet',     'lorem et ipsum dolor sit amet',     'lorem et ipsum dolor sit amet',     'lorem et ipsum dolor sit amet',   ] } 

store/getters.js

export default getpost = (state) => (postid) => {   return state.posts[postid] }  export default listfeaturedposts = (state, getters) => () => {   console.log(getters) // {}    return state.featuredposts.map(postid => getters.getpost(postid).substring(0, excerpt_length); } 

store/index.js

import vue 'vue' import vuex 'vuex' import state './state' import * getters './getters' import * mutations './mutations'  vue.use(vuex)  export default new vuex.store({   state,   getters,   mutations }) 

according documentation, getters parameter can used access other getters. however, when try access getters inside listfeaturedposts, it's empty, , error in console due getters.getpost being undefined in context.

how call getpost vuex getter inside listfeaturedposts in example above?


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -