vue實(shí)現(xiàn)在線學(xué)生錄入系統(tǒng)
最近一直在學(xué)Vue,這次做了一個(gè)簡(jiǎn)單的在線學(xué)生信息錄入系統(tǒng)來鞏固一下所學(xué)知識(shí)。
因?yàn)橹饕庆柟蘓ue的知識(shí),所以數(shù)據(jù)也沒放數(shù)據(jù)庫,也沒用JavaBean或者Servlet,直接寫死到表單里了。
具體頁面是這樣的:
先羅列一下其中用到的Vue的知識(shí)點(diǎn):
①v-for指令的使用
②v-model指令的使用
③v-on/@click指令的使用
再提一下可能會(huì)用到的知識(shí)點(diǎn):
①JavaScript中對(duì)數(shù)組頭添元素的unshift()方法
②JavaScript中對(duì)數(shù)組刪除元素的splice()刪除方法
上一下代碼,大家結(jié)合上面我羅列的知識(shí)點(diǎn),就能很容易看懂它:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>在線學(xué)生信息錄入</title> <style> /*css樣式設(shè)置 */ #app { margin: 50px auto; width: 600px; } fieldset { border: 10px solid pink; margin-bottom: 30px; } fieldset input { width: 200px; height: 30px; margin: 10px 0px; } table { width: 600px; border: 2px solid pink; text-align: center; } thead { background-color: pink; } </style> </head> <body> <div id="app"> <!--信息輸入框--> <fieldset> <legend>學(xué)生錄入系統(tǒng)</legend> <div> <div><span>姓名:</span> <!--用v-model指令綁定輸入的信息,更新到表格--> <input type="text" placeholder="請(qǐng)輸入姓名" v-model=" newMessage.name"> </div> <div><span>年齡:</span> <input type="text" placeholder="請(qǐng)輸入年齡" v-model=" newMessage.age"> </div> <div> <span>性別:</span> <select v-model=" newMessage.sex"> <option value="男">男</option> <option value="女">女</option> </select> </div> <div> <span>電話:</span> <input type="text" placeholder="請(qǐng)輸入電話號(hào)碼" v-model=" newMessage.phone"> </div> </div> <button @click="createNewMessage()">創(chuàng)建新用戶</button> </fieldset> <!--信息顯示框--> <table> <thead> <tr> <td>姓名</td> <td>性別</td> <td>年齡</td> <td>電話</td> <td>刪除</td> </tr> </thead> <tbody> <tr v-for="(i,index) in persons"> <td>{{i.name}}</td> <td>{{i.sex}}</td> <td>{{i.age}}</td> <td>{{i.phone}}</td> <td> <button @click=" deleteStuMessage(index)">刪除</button> </td> </tr> </tbody> </table> </div> <script src="vue.min.js"></script> <script> new Vue({ el: '#app', data: { persons: [ {name: '王舞', age: 20, sex: '女', phone: '13547878787'}, {name: '青峰', age: 22, sex: '男', phone: '13547878784'}, {name: '小倩', age: 24, sex: '女', phone: '13547878781'}, {name: '阿航', age: 22, sex: '男', phone: '13547878786'}, ], newMessage: {name: '', age: '', sex: '男', phone: ''} }, methods: { // 創(chuàng)建新記錄 createNewMessage() { //添加約束 if (this.newMessage.name === "") { alert("請(qǐng)輸入姓名!"); return; } if (this.newMessage.age <= 0) { alert("請(qǐng)輸入正確年齡!"); return; } if (this.newMessage.phone === "") { alert("請(qǐng)?zhí)顚懯謾C(jī)號(hào)碼!"); return; } //用數(shù)組的unshift方法將新創(chuàng)建的信息加到表頭 this.persons.unshift(this.newMessage); //清空數(shù)據(jù) this.newMessage = {name: '', age: '', sex: '男', phone: ''}; }, //刪除記錄 deleteStuMessage(index) { this.persons.splice(index, 1); } }, }); </script> </body> </html>
更多文章可以點(diǎn)擊《Vue.js前端組件學(xué)習(xí)教程》學(xué)習(xí)閱讀。
關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請(qǐng)閱讀專題《vue實(shí)戰(zhàn)教程》
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue.js結(jié)合Ueditor富文本編輯器的實(shí)例代碼
本篇文章主要介紹了Vue.js結(jié)合Ueditor的項(xiàng)目實(shí)例代碼,這里整理了詳細(xì)的代碼,具有一定的參考價(jià)值,有興趣的可以了解一下2017-07-07vue.js使用v-model實(shí)現(xiàn)父子組件間的雙向通信示例
這篇文章主要介紹了vue.js使用v-model實(shí)現(xiàn)父子組件間的雙向通信,結(jié)合實(shí)例形式分析了vue.js基于v-model父子組件間的雙向通信的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2020-02-02vue 實(shí)現(xiàn)把路由單獨(dú)分離出來
這篇文章主要介紹了vue 實(shí)現(xiàn)把路由單獨(dú)分離出來,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-08-08vue如何處理base64格式文件pdf及圖片預(yù)覽功能
這篇文章主要給大家介紹了關(guān)于vue如何處理base64格式文件pdf及圖片預(yù)覽功能的相關(guān)資料,圖片的base64編碼就是可以將一副圖片數(shù)據(jù)編碼成一串字符串,使用該字符串代替圖像地址,需要的朋友可以參考下2024-05-05Vue-router不允許導(dǎo)航到當(dāng)前位置(/path)錯(cuò)誤原因以及修復(fù)方式
本文主要介紹了Vue-router不允許導(dǎo)航到當(dāng)前位置(/path)錯(cuò)誤原因以及修復(fù)方式,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09vue基于session和github-oauth2實(shí)現(xiàn)登錄注冊(cè)驗(yàn)證思路詳解
通過 sessionId 可以在 session 表中獲取用戶的信息,此外,還利用 session 表實(shí)現(xiàn)了GitHub 的 OAuth2 第三方登錄,本文講解前端通過簡(jiǎn)單的方式實(shí)現(xiàn)一個(gè)基本的登錄注冊(cè)驗(yàn)證功能,感興趣的朋友跟隨小編一起看看吧2024-08-08