B
B
bormor2018-07-06 07:06:52
JavaScript
bormor, 2018-07-06 07:06:52

vue router. How to communicate with a component in a route without using Vuex?

The option to get a parameter from the route and request data from the REST API on it seems, if not a crutch, then not always optimal.
How can you receive and pass component data for a route using props and $emit?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2018-07-06
@bormor

In any component, the root Vue is available via this.$root, although the documentation insists that it's better to switch to vuex instead .
You can store data in this.$root.$dataas an option. Write them there directly, or, more gently, call events on the root from the component:

this.$root.$emit('formFilled', {name:"Ivan", job:"developer"})

I
Ilya, 2018-07-06
@ilyapashkov02

it's not like a crutch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question