1

Following is my function call:

await this.faqs({'fields.page': page, ...filters});

and function is:

async faqs({state, commit}, filters) {

const {items} = await fetchData({content_type: state.contentType, ...filters});

const faqs = items.map((item) => {
  return {
    id: item.systemId,
    ...item.fields,
  };
});

commit('setFaqs', faqs);

return faqs;}

I want to pass two more parameters along with this rest operator. How can I do that?

3
  • I don't think your code snippets do what you think they do. Commented Sep 23, 2020 at 12:36
  • if the function is async faqs({ state, commit }, filters) { ... } then there is no rest parameter; filters seems to be an array maybe? so the calls looks like this.faqs({ state: ..., commit: ... }, [ ... ]) where [...] is an array of filters of you can pass. hard to tell without seeing more code. Commented Sep 23, 2020 at 14:31
  • @Thankyou , I have updated the question. Commented Sep 23, 2020 at 15:17

1 Answer 1

2

create an object and let it have 2 named keys and they use then use the spread operator for filters , like so:

await this.faqs({'fields.page': page, param1: 'someparam1', param2: 'someparam2', ...filters });
Sign up to request clarification or add additional context in comments.

5 Comments

{a: 1, {b: 2, c: 3}} is not valid syntax.
@Olian04 took off the brackets , hope thats fine
@AlexanderSolonik, How can I access it in function?
@Trupti async faqs({state, commit}, param1, param2, filters) like so, try it and let me know
@AlexanderSolonik, in console.log(param1);... it gives output as {'fields.page': page, param1: 'someparam1', param2: 'someparam2'} ... and console.log(filters) as undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.