T
T
Tenebrius2018-09-21 17:22:37
Vue.js
Tenebrius, 2018-09-21 17:22:37

How to change the data in the model?

As far as I understand, in the second version of VUE, the two-way binding was abolished.
Data is passed down (from an ancestor to a descendant), events bubble up.
Actually the question is how to change the data of the parent element?
For example, something like a group of radio buttons, when clicking in the model, the value of the property that stores the id of the selected element should change. How to do it?
https://jsfiddle.net/Tenebrius/pjt6fcg0/20/
The main model object is arr , the selectedTagId property should change .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-21
@Tenebrius

Hang a click handler on the smth-tag, pass the id of the selected element to it, and the group to which the element belongs, set the selectedTagId. Everything .
UPD. Taken from the comments:
No, it's absurd. That is, you can, of course, knock on $root / $parent from the child component and change something there, but you DO NOT need to do this. The data is in the root component - change it there.
Or did you mean dispatching an event from a child component? Forwarding the event through smth-group will not work, because event handlers cannot be assigned to slots. There remains the option with the event bus (well, vuex too), but in the general case, it still won’t work, since smth-tag does not know which group its data belongs to (however, if it is guaranteed that id is unique not only within the group , but in general - then it is possible, for example like this ).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question