E
E
Erl2020-10-19 20:31:19
RESTful API
Erl, 2020-10-19 20:31:19

How to pass parameter to vuex?

There is a component that I get to through the vue router, I want to take the $router.url parameter and call an axios request that is located in store.js for example

async GET_INDEX_ARTICLES({ commit }) {
      return axios("https://rest.api/articles?_sort=created_at:desc&publish=true&_limit=$router.url", {
        method: "GET",
      })
        .then((response) => {
          commit("SET_INDEX_ARTICLES", response.data);
        })
        .catch((error) => {
          console.log("Exception: ", error);
          commit("SET_ERROR", error.true);
        });
    },

and let's say I want to dynamically change the limit parameter, how can I get this variable in vuex and insert it into the request

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-10-19
@NooBiToo

Move the router instance to a separate file.
Connect it in the vuex module where you need it: And use it.
import router from '@/router'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question