I have the following code, which accepts a slot containing an HTML field to be repeated:
When I use removeRow(index)
, it always removes the last slot. I've tested using and the correct input was removed here, but the correct slot was never removed.
I don't need the input in the slot to be dynamic or interact with Vue, I just want to allow the user to dynamically add/remove rows via the Vue component.
Please take a look at the two methods I use to add/remove rows below, in case this is the problem:
removeRow(index){ this.rows.splice(index, 1); }, addRow(){ this.rows.push({value: 'test'}) }
Any help is greatly appreciated.
Add a unique
key
value to yourv-for
loop element:This ensures that elements are correctly removed from the DOM.