相关版实例代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>vue实例:添加删除元素r</title> <style type="text/css"> .form-group{ margin:10px; } .form-group>label{ display: inline-block; width: 5rem; text-align: right; } </style> </head> <body> <div id="app"> <div class="form-group"> <label>name:</label> <input type="text" name="" v-model='newitems.name'> </div> <div class="form-group"> <label>age:</label> <input type="text" name="" v-model='newitems.age'> </div> <div class="form-group"> <label>sex:</label> <select v-model='newitems.sex'> <option value="男">男</option> <option value="女">女</option> </select> </div> <div class="form-group"> <label></label> <button v-on:click = 'addPerson'>Create</button> </div> <table> <thead> <tr> <th>Name</th> <th>Age</th> <th>Sex</th> <th>Delete</th> </tr> </thead> <tbody> <tr v-for="item in items"><!--v-for--> <td>{{item.name}}</td> <td>{{item.age}}</td> <td>{{item.sex}}</td> <td><button @click="deletePerson($index)">Delete</button></td> </tr> </tbody> </table> </div> </body> <script src="/UploadFiles/2021-04-02/vue.js">大家可以测试以下,感谢大家对的支持。