B
B
birdzxc2021-10-04 01:34:08
Vue.js
birdzxc, 2021-10-04 01:34:08

How to pass data through vuex to router?

Good afternoon. With the help of getters, data is not passed to the router-link and the data is not written to the array. If you make a basket on the same page as the catalog, then everything is perfectly written into the basket array. Can you provide some implementation examples? In the router itself, I indicated the transfer of props.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-10-04
@birdzxc

data is not sent to router-link

And what kind of data? Why didn't they show it (and not only the data - I don't see a line of code)? Are you trying to shove an object by chance? - if so, then most likely everything is transmitted, but the data turns into garbage. The fact is that the router converts the parameter values ​​to strings (except for arrays - they will remain arrays, their elements will be turned into strings). Accordingly, if further you try to extract some properties from the received string or strings (of course, from those that the strings do not have), you will get undefined.
If you make a basket on the same page as the catalog, then everything is perfectly written into the basket array.

I don't understand what exactly you are trying to do. I see two options, and both delusional.
1. You are trying to add an item to your shopping cart by clicking on a link. If so, you don’t need to go anywhere, instead router-linkmake a button, by clicking on which the corresponding action or mutation will immediately be called.
2. You are trying to router-linkpass an array of items added to the cart to the cart component. If so, don't pass anything, let the cart component pick up the data directly from vuex.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question