Vue学生管理系统 v2.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | <!DOCTYPE html> <html lang= "zh-CN" > <head> <meta charset= "utf-8" > <meta http-equiv= "X-UA-Compatible" content= "IE=edge" > <meta name= "viewport" content= "width=device-width, initial-scale=1" > <title>学生管理系统</title> <link href= "../public/css/bootstrap.min.css" rel= "stylesheet" > <link href= "../public/css/style.css" rel= "stylesheet" > <script src= "https://cdn.jsdelivr.net/npm/vue@2" ></script> <style> .row>div { border: 1px solid #000; } .modal { display: block; opacity: 1; top: 100px; overflow: visible; } </style> </head> <body> <div id= "app" > <div class = "container" > <table class = "table table-striped" > <caption>学生管理系统v1.0-展示学生</caption> <tr> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>操作</th> </tr> <tr v- for = "item,index in arr" :key= "index" > <td>{{item.name}}</td> <td>{{item.age}}</td> <td>{{item.gender}}</td> <td><button @click= "del(index,item.name)" class = "btn btn-danger btn-xs" data-toggle= "modal" data-target= "#exampleModal" data-whatever= "@mdo" >删除</button></td> </tr> </table> <hr> <hr> <hr> <form action= "" > <table class = "table table-striped" > <caption>添加学生信息</caption> <tr> <td>项目</td> <td>信息</td> </tr> <tr> <td>姓名</td> <td> <input type= "text" class = "form-control" id= "stuname" placeholder= "姓名" v-model= "stuname" > </td> </tr> <tr> <td>年龄</td> <td> <input type= "number" class = "form-control" id= "stuage" placeholder= "年龄" v-model= "stuage" > </td> </tr> <tr> <td>性别</td> <td> <label class = "gen-span" ><input type= "radio" class = "radio-info" v-model= "gender" checked value= "男" > 男</label> <label class = "gen-span" ><input type= "radio" class = "radio-info" v-model= "gender" value= "女" > 女</label> <label class = "gen-span" ><input type= "radio" class = "radio-info" v-model= "gender" value= "保密" > 保密</label> </td> </tr> </table> <div style= "text-align: center;" ><input @click= "add" type= "button" class = "btn btn-info btn-sm add-btn" value= "确定增加" /></div> </form> </div> <!-- 插入组件 --> <!-- 2.接收父组件的值 --> <!-- 2.自定义函数 --> <!-- 属性名和标签名都不能驼峰 --> <modal :isshow= "isShow" :arrname= "arrName" :arrindex= "arrIndex" @fn= "change" @close= "Close" ></modal> </div> <!-- 创建模板 --> <template id= "modal" > <div v-show= "isshow" class = "modal fade" id= "exampleModal" tabindex= "-1" role= "dialog" aria-labelledby= "exampleModalLabel" > <div class = "modal-dialog" role= "document" > <div class = "modal-content" > <div class = "modal-header" > <button type= "button" class = "close" data-dismiss= "modal" aria-label= "Close" ><span aria-hidden= "true" @click= "fn" >×</span></button> <h4 class = "modal-title" id= "exampleModalLabel" >确认框</h4> </div> <div class = "modal-body" > <form> <div class = "form-group" > <label for = "message-text" class = "control-label" >确定要删除<strong class = "control-label-name" style= "color:blue" >{{arrname}}</strong>吗?</label> </div> </form> </div> <div class = "modal-footer" > <button type= "button" class = "btn btn-default" data-dismiss= "modal" @click= "fn" >返回</button> <a href= "###" class = "delete-a" ><button type= "button" class = "btn btn-primary" @click= "realDel(arrindex)" >确认</button></a> </div> </div> </div> </div> </template> <script> //子组件 let modal = { template: '#modal' , //1.自定义属性 props: [ 'isshow' , 'arrname' , 'arrindex' ], methods: { //确认删除 //3.传值改变父组件 realDel(i) { this .$emit( 'fn' , i) }, //取消传值 fn() { this .$emit( 'close' ) } } } //父组件 new Vue({ el: "#app" , data: { //显示隐藏模态框 isShow: false , //渲染列表 arr: [ { name: '小明' , age: 12, gender: "男" }, { name: '小红' , age: 10, gender: "女" }, { name: '小刚' , age: 16, gender: "保密" } ], //姓名 stuname: '' , //年龄 stuage: '' , //性别 gender: '男' , //数组名字 arrName: '' , //数组下标 arrIndex: 0 }, created() { console.log( '加载' ); //获取存储的数据 //判断数据有没有 this .arr = JSON.parse(localStorage.getItem( 'arr' )) || this .arr }, //注册组件 components: { modal: modal }, methods: { //添加人员 add() { //判断是否为空 if (! this .stuname.trim() || ! this .stuage.trim()) { alert( '请输入正确的数据' ) //重置 this .stuage = '' ; this .stuname = '' ; this .gender = "男" return } //添加数据 this .arr.push({ name: this .stuname.trim(), age: this .stuage.trim(), gender: this .gender }) //重置 this .stuage = '' ; this .stuname = '' ; this .gender = "男" ; //数据存储到本地 localStorage.setItem( 'arr' , JSON.stringify( this .arr)); }, //删除键弹出层 del(i, name) { this .isShow = ! this .isShow; this .arrName = name this .arrIndex = i }, //1.自定义函数给子组件调用 change(i) { this .arr.splice(i, 1); this .isShow = ! this .isShow; //数据存储到本地 localStorage.setItem( 'arr' , JSON.stringify( this .arr)); }, Close() { //点击返回或者交叉的时候传值 this .isShow = ! this .isShow; } } }) </script> </body> </html> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具