Have you ever wondered how to create a Vuex store getter that takes a parameter argument? Check out this example: https://vuex.vuejs.org/en/getters.html
I'm currently working on a project using Typescript (https://github.com/hmexx/vue_typescript_starter_kit), and I'm facing a challenge in writing a getter that accepts a parameter argument. The code snippet below illustrates my attempt, but it doesn't seem to work as expected:
export function getItemById(state : State, id : Number) : MyItem | undefined {
if(id === undefined) {
return undefined;
}
for(const item of state.items) {
if(item.id === id) {
return item;
}
}
return undefined;
}
export default <GetterTree<State, any>> {
getItemById
};