I'm trying to make a list of items that provides an input and a color picker. It should always have an empty element at the end of the list.
Elements are populated with objects that are stored in data.
Everything is OK, I do a simple method that filters objects with empty value, then add a new one.
But, when the user set empty value on an element that is not the last one:
- the "data" values is well ordered, empty value is removed
- but the view keeps the "key", so the elment is still here
This is what I do on the parent Vue:
addEmptyElement() {
// now find any empty values
this.values = this.values.filter((v) => v.length);
// and append an empty one
this.values.push("");
},
And the values are use to bind Item component like this:
<Item
v-for="(v, i) in values"
:key="i"
v-bind:text="v"
@valueChanged="onItemChanged"
/>
The "valueChanged" event is emitted by Item and provides the position in the list and value that chaged.
I created a simpler example that you can check here:
https://codesandbox.io/s/vue-component-order-problem-rc4o1?file=/src/App.vue
To give some precision:
- The "Element" component "emit" value changes, so the parent knows which element changed
- I use
this.$.vnode.keyto have find the value to change in parent vue (that's maybe where there is a problem)
Maybe I did it wrong, with a bad implementation, so please, tell me what I badly do :)
Thanks !