[Vuejs]-How to send several action's parameters together with context to the url Vuex?

0👍

An action only accepts two params, context and payload.

So here you need to use object when passing multiple params.

async getFlights(context, { selectedPoint, departurePoint }) {
    
  const res = await fetch(
    `http://api.travelpayouts.com/v2/prices/month-matrix?currency=rub&origin=${selectedPoint}&destination=${departurePoint}&show_to_affiliates&token=${context.state.token}`,
  );
  if (res.ok) {
    let result = await res.json();
    context.commit('setFlights', result.data);
  }
  return res.ok;
},

When calling the action pass the values as an object.

https://vuex.vuejs.org/api/#actions

Leave a comment