How to dynamically add/remove slot fields based on arrays in Vue JS-PHP Chinese Network Q&A
How to dynamically add/remove slot fields based on arrays in Vue JS
P粉639667504
P粉639667504 2023-08-28 17:43:21
0
1
418

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.

P粉639667504
P粉639667504

reply all (1)
P粉463824410

Add a uniquekeyvalue to yourv-forloop element:

This ensures that elements are correctly removed from the DOM.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!