当前位置: 移动技术网 > IT编程>开发语言>JavaScript > vue实现员工信息录入功能

vue实现员工信息录入功能

2020年06月23日  | 移动技术网IT编程  | 我要评论

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>

 <div id="div2">

 <fieldset>
  <legend>员工信息录入</legend>


  <div >

  <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>

  </div>


  <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>


 </div>



</body>
<script src="js/vue.js"></script>
<script>

 var div1data={
 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:"#div2",
 data:div1data,

 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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网