vue實現(xiàn)戶籍管理系統(tǒng)
本文實例為大家分享了vue實現(xiàn)戶籍管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
戶籍管理系統(tǒng),v-model,v-for的引用
界面預覽

步驟思路:
1.html+css創(chuàng)建
2.引入vue,實例
3.準備默認數(shù)據(jù)message數(shù)組
4.渲染默認數(shù)據(jù),v-for循環(huán)表單
5.創(chuàng)建一條新數(shù)據(jù)newmessage
6.綁定到輸入框v-model
7.創(chuàng)建一個添加函數(shù)add(),把新數(shù)據(jù)添加到默認數(shù)據(jù)中,newmessage->message
8.添加完后,清空表單,即恢復newmessage
9.點誰刪誰del()函數(shù)
body部分:
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id = 'app' v-cloak>
<legend>戶籍管理系統(tǒng)</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>
</div>
vue部分:
<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>
*{
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>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue的表單數(shù)據(jù)收集案例之基本指令和自定義指令詳解
收集表單數(shù)據(jù)可以使用這個v-model實現(xiàn)這個數(shù)據(jù)的綁定,但是在有些輸入框中,還需要一些其他的指令搭配這個v-model指令結(jié)合使用,這篇文章主要介紹了vue的表單數(shù)據(jù)收集,基本指令和自定義指令,需要的朋友可以參考下2023-01-01
vue+elementUi中的table實現(xiàn)跨頁多選功能(示例詳解)
最近在開發(fā)工業(yè)品超市的后臺系統(tǒng),遇到一個需求,就是實現(xiàn)在一個table表格中多選數(shù)據(jù),在網(wǎng)上查了好多,有些方法真的是無語,下面通過本文給大家分享vue+elementUi中的table實現(xiàn)跨頁多選功能,感興趣的朋友跟隨小編一起看看吧2024-05-05
Vue3配置路由ERROR in [eslint]報錯問題及解決
這篇文章主要介紹了Vue3配置路由ERROR in [eslint]報錯問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10
vue項目刷新當前頁面的三種方式(重載當前頁面數(shù)據(jù))
這篇文章主要介紹了vue項目刷新當前頁面的三種方式(重載當前頁面數(shù)據(jù)),本文結(jié)合實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-01-01
vue改變數(shù)據(jù)后數(shù)據(jù)變化頁面不刷新的解決方法
這篇文章主要給大家介紹了關(guān)于vue改變數(shù)據(jù)后數(shù)據(jù)變化頁面不刷新的解決方法,vue比較常見的坑就是數(shù)據(jù)(后臺返回)更新了,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2023-07-07

