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 get arguments passed to getters

See original GitHub issue

How to get arguments passed to getters

for example:

const state = {
 users:[{id:1},{id:2}]
}
const getters = {
  getUser: state => id => state.users.find( el =>el.id == id )
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
championswimmercommented, Dec 9, 2018
@Module
class MyModule extends VuexModule {
  users = [{id:1},{id:2}]
  get user () {
    return (id => this.users.find( el =>el.id == id ))
  }
}
1reaction
Leiknircommented, Feb 14, 2019

Thanks a lot for this guys. May I suggest to include this example also in the project’s tests? I was googling everywhere for this, but couldn’t find the solution. Only when I wanted to create a new issue on this project, I’ve noticed this one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vuexjs getter with argument - Stack Overflow
You can pass arguments to getters by returning a function. This is particularly useful when you want to query an array in the...
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 >
How to pass parameters to the function in getters #688 - GitHub
anybody knows if is possible to load getters in component using mapGetters? I mean, instead of this return this.$store.getters.search('foo'). do ...
Read more >
Getters | Vuex
You can also pass arguments to getters by returning a function. This is particularly useful when you want to query an array in...
Read more >
How to pass parameters to a Vuex store getter
It seem that it's not possible to pass parameters to a getter, when it's being mapped by mapGetters. I've declared normally my getter...
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