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

步驟思路:
1.html+css創(chuàng)建
2.引入vue,實(shí)例
3.準(zhǔn)備默認(rèn)數(shù)據(jù)message數(shù)組
4.渲染默認(rèn)數(shù)據(jù),v-for循環(huán)表單
5.創(chuàng)建一條新數(shù)據(jù)newmessage
6.綁定到輸入框v-model
7.創(chuàng)建一個(gè)添加函數(shù)add(),把新數(shù)據(jù)添加到默認(rèn)數(shù)據(jù)中,newmessage->message
8.添加完后,清空表單,即恢復(fù)newmessage
9.點(diǎn)誰刪誰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>
手機(jī):<input type="text" placeholder="請輸入手機(jī)號" 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'>手機(jī)</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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue3.0+ts引入詳細(xì)步驟以及語法校驗(yàn)報(bào)錯問題解決辦法
Vue?3.0是一個(gè)非常流行的JavaScript框架,不僅易于學(xué)習(xí)和使用,而且可以與許多UI框架集成,下面這篇文章主要給大家介紹了關(guān)于vue3.0+ts引入詳細(xì)步驟以及語法校驗(yàn)報(bào)錯問題的解決辦法,需要的朋友可以參考下2024-01-01
Antd-vue Table組件添加Click事件,實(shí)現(xiàn)點(diǎn)擊某行數(shù)據(jù)教程
這篇文章主要介紹了Antd-vue Table組件添加Click事件,實(shí)現(xiàn)點(diǎn)擊某行數(shù)據(jù)教程,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
Vue手動埋點(diǎn)設(shè)計(jì)的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Vue手動埋點(diǎn)設(shè)計(jì)的相關(guān)資料,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,需要的朋友可以參考下2022-03-03
JavaScript之實(shí)現(xiàn)一個(gè)簡單的Vue示例
這篇文章主要介紹了JavaScript之實(shí)現(xiàn)一個(gè)簡單的Vue示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-01-01

