Article From:

1.Render lists have input boxes, write values in different input boxes, and when deleting, the values in the input boxes are not the desired result

When I delete the second item, I need the result to be 1 in the first input box and 3 in the last.

<!DOCTYPE html>
    <meta charset="UTF-8">
    <script type="text/javascript" src=""></script>
     <script type="text/javascript" src=""></script>
<div id="test">
    <div v-for="(item,index) in items">
        <div >
            <input type="" name="" v-model="arr[index]">
            <span v-text="Math.random()*10"></span>
        <button @click="deleteItem(index,$event)">Delete < /button>< /div>< button @click= "addItem" > new < /button>< /div>< script type= "text/javascript" >Var VM = new Vue ({)El: "#test",Data:{Items:[],Keyword:1,Arr:[]},Methods:{AddItem:function () {This.items.push ({});},DeleteItem:Function (index, event) {/ / var $current = $(;/ / $currenT.prev ().Attr ('key', 2);This.items.splice (index, 1);}}})≪ /script>< /body>< /html>

Answer 0:

In your case, data is stored inarr So, your code is slightly changed.

staythis.items.splice(index,1); Add one line below:


You can achieve the effect you want.

Leave a Reply

Your email address will not be published. Required fields are marked *