Home > Article > Web Front-end > Example analysis of Vue implementation of household registration management system
The example in this article shares with you the specific code of Vue to implement the household registration management system for your reference. The specific content is as follows
Household registration management system, v-model, v- Reference for for
Interface preview
Step ideas:
1.html css creation
2.Introduce vue, example
3.Prepare default data message array
4.Render default data, v-for loop form
5.Create a new data newmessage
6. Bind to the input box v-model
7. Create an add function add() to add new data to the default data, newmessage->message
8. After adding, clear the form and restore newmessage
9. Click who deletes whom del() function
body part:
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <p id = 'app' v-cloak> <legend>户籍管理系统</legend></br> 姓名:<input type="text" placeholder="请输入用户名" v-model = 'newmessage.name'></br> 年龄:<input type="text" placeholder="请输入年龄" v-model = 'newmessage.age'></br> 性别: <select v-model = 'newmessage.sex'> <option>男</option> <option>女</option> </select></br> 手机:<input type="text" placeholder="请输入手机号" v-model = 'newmessage.phone'></br> <button class = 'save' @click = 'add()'>保存至用户</button></br> <table> <tr class = 'title'> <td width = '100px'>姓名</td> <td width = '100px'>性别</td> <td width = '100px'>年龄</td> <td width = '200px'>手机</td> <td width = '100px'>删除</td> </tr> <tr v-for = 'item,index in message'> <td>{{item.name}}</td> <td>{{item.sex}}</td> <td>{{item.age}}</td> <td>{{item.phone}}</td> <td><button @click = 'del(index)'>删除</button></td> </tr> </table> </p>
vue part:
<script> var app = new Vue({ el:'#app', data:{ message:[ { name:'张三', sex:'女', age:16, phone:'1568888811' }, { name:'李四', sex:'男', age:26, phone:'1456666622' }, { name:'王麻子', sex:'女', age:36, phone:'1866666666' }, ], newmessage:{name:'',age:'',sex:'男',phone:''}, }, methods:{ add(){ if(!this.newmessage.name == ''){ this.message.push(this.newmessage); this.newmessage = { name:'', age:'', sex:'男', phone:'' }; } else{ alert('请输入姓名!'); } }, del(index){ this.message.splice(index,1); } } }) </script>
css style:
<style> *{ margin:0; padding:0; } #app{ border: 1px solid black; width:800px; padding:30px 30px; } #app .save{ background-color: #555555; border-radius: 10%; height:50px; color:white; } #app input,select{ margin:10px 0; width:300px; } #app td{ text-align: center; } #app .title td{ background-color: #555555; color:white; } #app table button{ background-color: #555555; color:white; border-radius: 30%; } </style>
Related learning recommendations: javascript video tutorial
The above is the detailed content of Example analysis of Vue implementation of household registration management system. For more information, please follow other related articles on the PHP Chinese website!