如何使用vue实现员工信息录入功能?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
Vue通用信息录入界面,供大家参考,具体内容如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>员工信息录入</title>
<style>
.btn1{
color: blue;
background: skyblue;
text-align: center;
}
</style>
</head>
<body>
<p id="p2">
<fieldset>
<legend>员工信息录入</legend>
<p >
<label>姓名:</label>
<input type="text" v-model="newStudent.name"><br>
<label>年龄:</label>
<input type="text" v-model="newStudent.age"><br>
<label>性别:</label>
<select v-model="newStudent.sex">>
<option value="男">男</option>
<option value="女">女</option>
</select><br>
<label>手机:</label>
<input type="text" v-model="newStudent.phoneNo"><br>
<p>
<button @click="createStudent()">新增用户</button>
</p>
</p>
<table border="2px">
<thead>
<tr>
<th>序号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>手机</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="(student,index) in studentsList">
<td>{{index+1}}</td>
<td>{{student.name}}</td>
<td>{{student.age}}</td>
<td>{{student.sex}}</td>
<td>{{student.phoneNo}}</td>
<td :class="btn1"><button @click="DeletestudentRow(index)">移除</button></td>
</tr>
</tbody>
</table>
<label>总行数:</label><span>{{studentsList.length}}</span>
</fieldset>
</p>
</body>
<script src="js/vue.js"></script>
<script>
var p1Data={
newStudent:{name:"",age:0,sex:"男",phoneNo:""},
studentsList:[{No:"0001",name:"张三",age:18,sex:"男",phoneNo:"13688899900"},
{No:"0112",name:"王五",age:28,sex:"男",phoneNo:"18800068888"},
{No:"0253",name:"林志玲",age:33,sex:"女",phoneNo:"18600001002"},
{No:"0608",name:"林志颖",age:68,sex:"男",phoneNo:"15998769900"}],
};
var vm1=new Vue({
el:"#p2",
data:p1Data,
methods:{
//移除一行
DeletestudentRow:function (index) {
this.studentsList.splice(index,1);
},
//添加一行
createStudent: function(){
this.studentsList.push(this.newStudent);
// 添加完newPerson对象后,重置newPerson对象
this.newStudent = {name:"",age:0,sex:"男",phoneNo:""}
},
}
});
</script>
</html>
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。