[Vuejs]-How do you pass a variable to a Promise.All function?

2👍

const is block scoped. So, filter is actually undefined outside of the if braces. Notice the error in this snippet:

const query = { filter: '' }

if (query.filter) {
  const filter = '&filter=' + query.filter;
} else {
  const filter = '';
}

console.log(filter)

To fix it, you want filter to be defined outside of a block, which can still be achieved with const using a ternary in this case:

const filter = query.filter ? `&filter=${query.filter}` : '';

const [companyResponse, requestsResponse] = await Promise.all([
  // API Call "Read a company"
  $axios.$get('/companies/' + params.company),

  // API Call "List a companies requests"
  $axios.$get('/companies/' + params.company + '/requests?count=5&include=owner' + filter)
]);

1👍

Because you defined filter in an if statement. Do this before the if statement:

let filter

Then remove “const” from the if and else blocks.

Leave a comment