vue實(shí)現(xiàn)表單錄入小案例
本文實(shí)例為大家分享了vue實(shí)現(xiàn)表單錄入的具體代碼,供大家參考,具體內(nèi)容如下
最終效果:
代碼:
<template> <div id="app"> <!--第一部分--> <fieldset> <legend>學(xué)生錄入系統(tǒng)</legend> <div> <span>姓名:</span> <input type="text" placeholder="請(qǐng)輸入姓名" v-model="newStudent.name"> </div> <div> <span>年齡:</span> <input type="text" placeholder="請(qǐng)輸入年齡" v-model="newStudent.age"> </div> <div> <span>性別:</span> <select v-model="newStudent.sex"> <option value="男">男</option> <option value="女">女</option> </select> </div> <div> <span>手機(jī):</span> <input type="text" placeholder="請(qǐng)輸入手機(jī)號(hào)碼" v-model="newStudent.phone"> </div> <button @click="createNewStudent()">創(chuàng)建新用戶</button> </fieldset> <!--第二部分--> <table> <thead> <tr> <td>姓名</td> <td>性別</td> <td>年齡</td> <td>手機(jī)</td> <td>刪除</td> </tr> </thead> <tbody> <tr v-for="(p, index) in persons"> <td>{{p.name}}</td> <td>{{p.sex}}</td> <td>{{p.age}}</td> <td>{{p.phone}}</td> <td> <button @click="deleteStudentMsg(index)">刪除</button> </td> </tr> </tbody> </table> </div> </template> <script> export default { name: "todolist2", data(){ return{ persons: [ {name: '張三', age: 20, sex: '男', phone: '18932323232'}, {name: '李四', age: 30, sex: '男', phone: '18921212122'}, {name: '王五', age: 20, sex: '男', phone: '18932223232'}, {name: '趙六', age: 25, sex: '女', phone: '18932322232'}, ], newStudent: {name: '', age: 0, sex: '男', phone: ''} } }, methods: { // 創(chuàng)建一條新紀(jì)錄 createNewStudent(){ // 姓名不能為空 if(this.newStudent.name === ''){ alert('姓名不能為空'); return; } // 年齡不能小于0 if(this.newStudent.age <= 0){ alert('請(qǐng)輸入正確的年齡'); return; } // 手機(jī)號(hào)碼 if(this.newStudent.phone === ''){ alert('手機(jī)號(hào)碼不正確'); return; } // 往數(shù)組中添加一條新紀(jì)錄 this.persons.unshift(this.newStudent); // 清空數(shù)據(jù) this.newStudent = {name: '', age: 0, sex: '男', phone: ''} }, // 刪除一條學(xué)生紀(jì)錄 deleteStudentMsg(index){ this.persons.splice(index,1); } }, } </script> <style scoped> #app{ margin: 50px auto; width: 600px; } fieldset{ border: 1px solid orangered; margin-bottom: 20px; } fieldset input{ width: 200px; height: 30px; margin: 10px 0; } table{ width: 600px; border: 2px solid orangered; text-align: center; } thead{ background-color: orangered; } </style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue axios 中提交表單數(shù)據(jù)(含上傳文件)
- Vue表單驗(yàn)證插件Vue Validator使用方法詳解
- Vue+ElementUI實(shí)現(xiàn)表單動(dòng)態(tài)渲染、可視化配置的方法
- Vue ElementUI之Form表單驗(yàn)證遇到的問(wèn)題
- Vue form 表單提交+ajax異步請(qǐng)求+分頁(yè)效果
- vue表單驗(yàn)證你真的會(huì)了嗎?vue表單驗(yàn)證(form)validate
- 使用Vue動(dòng)態(tài)生成form表單的實(shí)例代碼
- Vue2.0表單校驗(yàn)組件vee-validate的使用詳解
- vue使用Element組件時(shí)v-for循環(huán)里的表單項(xiàng)驗(yàn)證方法
- vue2 中如何實(shí)現(xiàn)動(dòng)態(tài)表單增刪改查實(shí)例
相關(guān)文章
Vue+Node.js+WebSocket實(shí)現(xiàn)即時(shí)通訊
本文主要介紹了Vue+Node.js+WebSocket實(shí)現(xiàn)即時(shí)通訊,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05vue element插件this.$confirm用法及說(shuō)明(取消也可以發(fā)請(qǐng)求)
這篇文章主要介紹了vue element插件this.$confirm用法及說(shuō)明(取消也可以發(fā)請(qǐng)求),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10Vue+springboot批量刪除功能實(shí)現(xiàn)代碼
這篇文章主要介紹了Vue+springboot批量刪除功能,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-05-05vue-cli基礎(chǔ)配置及webpack配置修改的完整步驟
這篇文章主要給大家介紹了關(guān)于vue-cli基礎(chǔ)配置及webpack配置修改的完整步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者使用vue-cli具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10vue中使用localstorage來(lái)存儲(chǔ)頁(yè)面信息
這篇文章主要介紹了vue中使用localstorage來(lái)存儲(chǔ)頁(yè)面信息,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11vue項(xiàng)目中解決 IOS + H5 滑動(dòng)邊界橡皮筋彈性效果(解決思路)
最近遇到一個(gè)問(wèn)題,我們?cè)谄髽I(yè)微信中的 H5 項(xiàng)目中需要用到table表格(支持懶加載 上劃加載數(shù)據(jù)),但是他們?cè)阪i頭、鎖列的情況下,依舊會(huì)出現(xiàn)邊界橡皮筋效果,這篇文章主要介紹了vue項(xiàng)目中解決 IOS + H5 滑動(dòng)邊界橡皮筋彈性效果,需要的朋友可以參考下2023-02-02