I'm trying to implement such algo using vueJS:
- We have two input fields, for example, we translate from one language to another. These two fields belongs to the two components that are made for easier integration;
- These two components are the same type and are in the one parent "host" component;
- Whenever we type something inside one component, it immediately being caught by the parent component and then translates using some algo to value for another one component. Then parent should put that value to the second child's field;
- Communication should be in two ways in both child components with their parent. I'm done with this algo, but I think I'm doing wrong.. I'm receiving warning that I mutate prop which is a bad idea. If you know the best way of doing such algo, PLS, advice it. Here is my implementation:
- Parent has two values: for the first input and for the second. They are bound to children' props using .sync modifier. Like this:
:value.sync="firstValue"and:value.sync="secondValue"; - Inside children we have prop named value(on which we sync our parent's data). Then we simply bind this prop using v-model:
v-model="value"; - And after all raise event for .sync updates:
@keyup="$emit('update:value', value);"; - On the parent bind some functions for events handling, that doesn't matter.
Again, algorithm performing well. But I think I'm doing bad with such things. I mutate prop value in each component using v-model, which isn't good. But .sync modifier won't work on value - I've checked, it only works on props, because v-bind only works on props as I can see... So, I'm very glad to hear advises for improvement..