vue實(shí)現(xiàn)學(xué)生錄入系統(tǒng)之添加刪除功能
一.案例代碼
<!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ì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
vue-router嵌套路由方式(頁面路徑跳轉(zhuǎn)但頁面顯示空白)
這篇文章主要介紹了vue-router嵌套路由方式(頁面路徑跳轉(zhuǎn)但頁面顯示空白),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
Vue之關(guān)于Eslint自動(dòng)加分號(hào)的問題及解決
這篇文章主要介紹了Vue之關(guān)于Eslint自動(dòng)加分號(hào)的問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
解決vue里a標(biāo)簽值解析變量,跳轉(zhuǎn)頁面,前面加默認(rèn)域名端口的問題
這篇文章主要介紹了解決vue里a標(biāo)簽值解析變量,跳轉(zhuǎn)頁面,前面加默認(rèn)域名端口的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07
Vue中使用echarts實(shí)現(xiàn)繪制人體動(dòng)態(tài)圖
這篇文章主要為大家詳細(xì)介紹了Vue中如何使用echarts實(shí)現(xiàn)繪制人體動(dòng)態(tài)圖,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-03-03
vuex實(shí)現(xiàn)登錄狀態(tài)的存儲(chǔ),未登錄狀態(tài)不允許瀏覽的方法
下面小編就為大家分享一篇vuex實(shí)現(xiàn)登錄狀態(tài)的存儲(chǔ),未登錄狀態(tài)不允許瀏覽的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03
vue3中實(shí)現(xiàn)音頻播放器APlayer的方法
這篇文章主要介紹了vue3中實(shí)現(xiàn)音頻播放器APlayer的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
vue中的provide/inject的學(xué)習(xí)使用
本篇文章主要介紹了vue中的provide/inject的學(xué)習(xí)使用,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05
vue.js通過自定義指令實(shí)現(xiàn)數(shù)據(jù)拉取更新的實(shí)現(xiàn)方法
數(shù)據(jù)拉取更新這個(gè)功能相信大家基本都見過,但是如果要做起來卻不止如何做起,所以這篇文章給大家分享了vue.js通過自定義指令實(shí)現(xiàn)的方法,閱讀本文需要對(duì)vue有一定理解,有需要的朋友們下面來一起看看吧。2016-10-10

