Vue.js实现可编辑的表格
(编辑:jimmy 日期: 2024/12/27 浏览:3 次 )
本文实例为大家分享了Vue.js实现可编辑的表格的具体代码,供大家参考,具体内容如下
<!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" type="text/css" href="bootstrap.min.css" > <style type="text/css"> table tr td{ text-align: center; } .btn-info{ margin-left: 5px; } .add,.addBox{ margin: 10px 0px 10px 10px; } .submit{ margin-left: 172px; } /*全删*/ .delAll{ margin-left: 10px; } /*新增*/ fieldset{ margin-left: 10px; } </style> </head> <body> <div id="app"> <button class="btn btn-primary btn-sm addBox" @click="addBox">添加</button> <button class="btn btn-sm btn-danger delAll" @click="delAll">批量删除</button> <table class="table table-bordered" > <thead> <tr> <td><input type="checkbox" @click="allSelect" v-model="checked"></td> <td>学号</td> <td>姓名</td> <td>年纪</td> <td>操作</td> </tr> </thead> <tbody> <tr v-for="person,index in people"> <td><input type="checkbox" v-model="selected" v-bind:value="person.sid"></td> <td @click="edit(index)" contenteditable="true">{{person.sid}}</td> <td @click="edit(index)" contenteditable="true">{{person.sname}}</td> <td @click="edit(index)" contenteditable="true">{{person.sage}}</td> <td><button @click="del(index)" class="btn btn-danger btn-sm">删除</button><button @click="update(index)" class="btn btn-info btn-sm">编辑</button></td> </tr> </tbody> </table> <fieldset v-show="seen" > <legend>新增用户</legend> <div class=""> <p> <label>学号:</label> <input type="text" v-model="newPeople.sid"> </p> <p> <label>姓名:</label> <input type="text" v-model="newPeople.sname"> </p> <p> <label>年龄:</label> <input type="number" v-model="newPeople.sage"> </p> <p> <button class="btn btn-success btn-sm submit" @click="add">提交</button> </p> </div> </fieldset> <!-- 编辑界面 --> <fieldset v-show="editSeen"> <legend>编辑用户</legend> <div class=""> <p> <label>学号:</label> <input type="text" v-model="editPeople.sid" value="{{sid}}"> </p> <p> <label>姓名:</label> <input type="text" v-model="editPeople.sname" value="{{sname}}"> </p> <p> <label>年龄:</label> <input type="number" v-model="editPeople.sage" value="{{sage}}"> </p> <p> <button class="btn btn-success btn-sm submit" @click="editSubmit">提交</button> </p> </div> </fieldset> </div> <script type="text/javascript" src="/UploadFiles/2021-04-02/vue.min.js">以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
下一篇:Vue.js 实现地址管理页面思路详解(地址添加、编辑、删除和设置默认地址)