最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實(shí)現(xiàn)學(xué)生錄入系統(tǒng)之添加刪除功能

 更新時(shí)間:2018年07月11日 10:42:12   作者:夏木炎  
本文給大家?guī)?lái)一個(gè)小案例基于vue實(shí)現(xiàn)學(xué)生錄入系統(tǒng)功能,代碼簡(jiǎn)單易懂非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

一.案例代碼

<!DOCTYPE html>
<html>
 <head>
 <meta charset="UTF-8">
 <title>vue指令綜合案例</title>
 <style>
  #app{
  margin: 50px auto;
  width: 620px;
  }
  fieldset{
  border: 2px solid plum;
  margin-bottom: 20px;
  }
  fieldset input{
  width: 200px;
  height: 30px;
  margin: 10px 0;
  }
  table{
  width: 620px;
  border: 2px solid plum;
  text-align: center;
  }
  thead{
  background-color: plum;
  }
  
 </style>
 </head>
 <body>
 <div id="app">
  <fieldset>
  <legend>學(xué)生錄入系統(tǒng)</legend>
  <div>
   <span>姓名:</span>
   <input type="text" placeholder="請(qǐng)輸入姓名" v-model="student.name"/>
   <span></span>
  </div>
  <div>
   <span>年齡:</span>
   <input type="text" placeholder="請(qǐng)輸入年齡" v-model="student.age"/>
  </div>
  <div>
   <span>性別:</span>
   <select v-model="student.sex">
   <option value="男">男</option>
   <option value="女">女</option>
   </select>
  </div>
  <div>
   <span>QQ:</span>
   <input type="text" placeholder="請(qǐng)輸入QQ" v-model="student.QQ"/>
  </div>
  <button @click="createNewStudent()">創(chuàng)建新用戶</button>
  </fieldset>
  <table>
  <thead>
   <tr>
   <td>姓名</td>
   <td>年齡</td>
   <td>性別</td>
   <td>QQ</td>
   <td>刪除</td>
   </tr>
  </thead>
  <tbody>
   <tr v-for="(p,index) in persons">
   <td>{{p.name}}</td>
   <td>{{p.age}}</td>
   <td>{{p.sex}}</td>
   <td>{{p.QQ}}</td>
   <td><button @click="deleteStudentMsg(index)">刪除</button></td>
   </tr>
  </tbody>
  </table>
 </div>
 <script type="text/javascript" src="js/jquery.js" ></script>
 <script type="text/javascript" src="js/vue.js" ></script>
 <script>
  //1.創(chuàng)建Vue的實(shí)例
  let vm=new Vue({
  el:'#app',
  data:{
   persons:[
    {name:'張三',age:16,sex:'男',QQ:'123456'},
    {name:'李四',age:17,sex:'男',QQ:'100000'},
    {name:'王麻子',age:18,sex:'女',QQ:'666666'},
    {name:'趙六',age:19,sex:'男',QQ:'888888'},
    {name:'劉七',age:20,sex:'女',QQ:'999999'}
   ],
   student:{name:'',age:0,sex:'男',QQ:''}
  },
  methods:{
   //創(chuàng)建一條新記錄
   createNewStudent(){
   //姓名不能為空
   if(this.student.name==''){
    alert('姓名不能為空');
    return;
   }
   //年齡不能小于0
   if(this.student.age<0){
    alert('請(qǐng)輸入正確年齡');
    return;
   }
   //QQ
   if(this.student.age==''){
    alert('請(qǐng)輸入正確年齡');
    return;
   }
   //往數(shù)組中添加一條新記錄
   this.persons.unshift(this.student);
   //清空數(shù)據(jù)
   this.student={name:'',age:0,sex:'男',QQ:''};
   },
   //刪除
   deleteStudentMsg(index){
   this.persons.splice(index,1);
   }
  }
  });
 </script>
 </body>
</html>

二.結(jié)果


總結(jié)

以上所述是小編給大家介紹的vue實(shí)現(xiàn)學(xué)生錄入系統(tǒng)之添加刪除功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論

马边| 潞城市| 甘谷县| 海阳市| 琼结县| 苏尼特右旗| 扶绥县| 安康市| 密云县| 延津县| 额敏县| 怀集县| 临沭县| 合肥市| 宁海县| 和田县| 辽源市| 龙州县| 和硕县| 孝昌县| 东丽区| 莆田市| 富平县| 固阳县| 图们市| 贺兰县| 广宗县| 丰宁| 新晃| 南平市| 辉县市| 柳河县| 绥中县| 明溪县| 呼图壁县| 如皋市| 邯郸县| 凯里市| 清新县| 营山县| 彭泽县|