question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use @Getter with Parameters

See original GitHub issue

If I have the following getter setup:

const getters: GetterTree<IMyState, any> = {
  // academies: (state, getters) => x.academies,
  academy: (s) => ((id: number) => s.items.find((x) => x.id === id)),
};

How can I use the @Getter decorator in my component to execute my getter based on a vue property:

@Component
export default class MyComponent extends Vue {
  @Prop({required: true})
  public id: number;

  @Getter
  public item
}

I want to bind the id property of my component and use @Getter to retrieve one of a collection of items.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
ktsncommented, Nov 3, 2017

Just call the getter.

@Component
export default class MyComponent extends Vue {
  @Prop({required: true})
  public id: number;

  @Getter
  public item: (id: number) => Item

  created() {
    console.log(this.item(this.id))
  }
}
3reactions
cnjackcommented, Oct 12, 2018

is done with

getUser: (state: DialogState) => (id: number): UserInfo => {
        for (const userInfo of state.userList) {
            if (userInfo.user_id === id) {
                return userInfo;
            }
        }
        return demoUser;
    },
Read more comments on GitHub >

github_iconTop Results From Across the Web

vuexjs getter with argument - Stack Overflow
getter is meant to do. first, as you can see in all the above examples the getter can be mapped as a computed...
Read more >
Getters | Vuex
Vuex allows us to define "getters" in the store. You can think of them as computed properties for stores. As of Vue 3.0,...
Read more >
How To Pass Arguments To The Vuex Getters
To do this we can use the "Method-Style Access" method provided by vuex. Using this defining method, we can send arguments to the...
Read more >
How to pass parameters to the function in getters #688 - GitHub
Use an Action to handle the api call. Update the store with a mutation. Use a getter to 'shape' the data into what's...
Read more >
Pass arguments to a Vuex getter - Jérémy Riverain
Passing arguments to a vuex getter is very useful. It makes them more powerful. However, the syntax to do it is quite tricky....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found