In a vue.js ponent (using vuex), I have:
puted: {...
filtered () {
return this.withFilters(obj1, obj2)
with withFilters
a getter to define in the store. But how in the store can I get the arguments passed to withFilters
and define this getter accordingly? For a 1-argument function I would have simply done something like
withFilter: state => obj1 => { ...
For example:
withFilter: state => obj1 => {
for (var k in obj1) {
obj1[k] !== null ? console.log('Not null!') : console.log('Null!')
}
}
Not sure how to do it with a 2-argument function.
In a vue.js ponent (using vuex), I have:
puted: {...
filtered () {
return this.withFilters(obj1, obj2)
with withFilters
a getter to define in the store. But how in the store can I get the arguments passed to withFilters
and define this getter accordingly? For a 1-argument function I would have simply done something like
withFilter: state => obj1 => { ...
For example:
withFilter: state => obj1 => {
for (var k in obj1) {
obj1[k] !== null ? console.log('Not null!') : console.log('Null!')
}
}
Not sure how to do it with a 2-argument function.
Share Improve this question asked Sep 6, 2018 at 0:11 WhyNotTryCalmerWhyNotTryCalmer 5066 silver badges18 bronze badges1 Answer
Reset to default 16You just need to define the function returned by your getter
with multiple arguments. For example
getters: {
withFilter (state) {
return (obj1, obj2) => {
// your code here
}
}
}
You could write this entirely with arrow functions but I think it looks messy (personal opinion)
withFilter: (state) => (obj1, obj2) => {
// your code here
}
See the documentation on ES6 arrow functions and argument parentheses here...
// Parentheses are optional when there's only one parameter name:
(singleParam) => { statements }
singleParam => { statements }