当前位置: 首页 > wzjs >正文

如皋网站建设招标前端外包

如皋网站建设招标,前端外包,企业注册资金变更流程,网站维护预算原创/朱季谦 最近通过Vue Element ui实现了动态表单功能,该功能还包括了动态表单新增行、删除行、动态表单验证、动态表单提交功能,趁热打铁,将开发心得记录下来,方便以后再遇到类似功能时,直接拿来应用。 简化的页…

原创/朱季谦

最近通过Vue + Element ui实现了动态表单功能,该功能还包括了动态表单新增行、删除行、动态表单验证、动态表单提交功能,趁热打铁,将开发心得记录下来,方便以后再遇到类似功能时,直接拿来应用。

简化的页面效果图如下:

image

最开始,我是用了纯粹的表格形式,后来发现,这种形式在提交的时候,不好对每个输入框做校验,若是表单形式话,就可以直接通过rule设置每个输入框的验证,因此,我就在表格里面嵌套了表单。注意一点是,el-form-item里的 :prop="scope.$index + '.name'"需要对应el-input的 v-model="studentData[scope.$index].name",两者都是同一个字段值。

<template><div ><div><div><el-button  size="small"  @click="addRow">新增</el-button></div><!--设置的表单--><el-form :model="studentData" ref="data" label-width="auto"><el-tableborder:header-cell-style="{ 'text-align': 'center' }":cell-style="{ 'text-align': 'center' }":data="studentData"ref="table"style="width: 100%"><el-table-column align="center"   label="姓名"><template slot-scope="scope"><!--表格里面嵌套表单--><el-form-item:prop="scope.$index + '.name'":rules="{ required: true, message: '姓名不能为空', trigger: 'blur' }"><el-inputv-model="studentData[scope.$index].name"autocomplete="off"size="small"placeholder="姓名"></el-input></el-form-item></template></el-table-column><el-table-column align="center"  label="年龄"><template slot-scope="scope"><el-form-item:prop="scope.$index + '.age'":rules="{ required: true, message: '年龄不能为空', trigger: 'blur' }"><el-inputv-model="studentData[scope.$index].age"autocomplete="off"size="small"type='number'placeholder="收款方开户行号"></el-input></el-form-item></template></el-table-column><el-table-column align="center"  label="性别"><template slot-scope="scope"><el-form-item:prop="scope.$index + '.sex'":rules="{ required: true, message: '性别不能为空', trigger: 'blur' }"><el-inputv-model="studentData[scope.$index].sex"autocomplete="off"size="small"placeholder="性别"></el-input></el-form-item></template></el-table-column><el-table-column fixed="right" label="操作" width="100"><template slot-scope="scope"><el-button@click="handleDeleteRow(studentData[scope.$index])"type="text"size="small">删除</el-button></template></el-table-column></el-table></el-form></div><div slot="footer" class="dialog-footer" style="margin-bottom: 10px"><el-button size="mini"  @click="submit">提交</el-button><el-button size="mini" @click="resetForm()">重置</el-button></div></div>
</template>

定义一个存储动态表格数据的数组变量

export default {data() {return {studentData:[],};},......
}

在methods方法里增加相关方法,分别是新增行、删除行、提交——

methods:{/*** 新增行*/addRow() {let index = this.studentData.length ;this.studentData.push({key: index,name:'',age:'',sex:'',});},/*** 删除行* @param row*/handleDeleteRow(row){let datas = this.studentData;for (var i = 0; i < datas.length; i++){if (datas[i].key == row.key){datas.splice(i,1);}}},/*** 提交*/submit() {this.$refs["data"].validate(valid => {//valid为true,表示表单都已经验证通过,若为false,说明存在表单验证失败if (valid) {save(this.studentData).then(response => {this.$message({message: '提交成功',type: 'success'});});}});},/*** 重置*/resetForm() {let datas = this.studentData;for (var i = 0; i < datas.length; i++){datas[i].name='';datas[i].age='';datas[i].sex='';}},
}

设置表单验证规则,可统一在rules设置,也可以在每一输入框单独设置,我这里是单独在每一个输入框里设置,即:rules="{ required: true, message: '姓名不能为空', trigger: 'blur' }"就可以了,当然,还可以做一些更复杂的自定义规则。

<el-table-column align="center"   label="姓名"><template slot-scope="scope"><!--表格里面嵌套表单--><el-form-item:prop="scope.$index + '.name'":rules="{ required: true, message: '姓名不能为空', trigger: 'blur' }"><el-inputv-model="studentData[scope.$index].name"autocomplete="off"size="small"placeholder="姓名"></el-input></el-form-item></template></el-table-column>

完成以上步骤,就可以快速写出一个基于Vue + Element ui 实现动态表单,包括新增行/删除行/动态表单验证/提交功能的逻辑。


文章转载自:

http://ziqPrs6F.rjcqb.cn
http://yFWs9BQa.rjcqb.cn
http://e315GRS2.rjcqb.cn
http://3sDXf09y.rjcqb.cn
http://mHXouCDo.rjcqb.cn
http://3QSty6ew.rjcqb.cn
http://nFcsREYx.rjcqb.cn
http://bBfVz2pq.rjcqb.cn
http://0cMnvTsz.rjcqb.cn
http://41XACLyH.rjcqb.cn
http://RlgdbDM9.rjcqb.cn
http://KtJ43SWg.rjcqb.cn
http://1uabo1h0.rjcqb.cn
http://4wKbb9b8.rjcqb.cn
http://jNflzJX2.rjcqb.cn
http://wwtjpaok.rjcqb.cn
http://b4ZWR9Rs.rjcqb.cn
http://BZtnD8rI.rjcqb.cn
http://InGTN4Zc.rjcqb.cn
http://GxQXMFbG.rjcqb.cn
http://aizPH0J8.rjcqb.cn
http://MuTdOGHC.rjcqb.cn
http://Zt5ieipQ.rjcqb.cn
http://rfdXRHpn.rjcqb.cn
http://C2AwhV7C.rjcqb.cn
http://FGwIFkUJ.rjcqb.cn
http://XaFe2aYV.rjcqb.cn
http://VTUEcZ1o.rjcqb.cn
http://DCvbBT7H.rjcqb.cn
http://5bUqmEFu.rjcqb.cn
http://www.dtcms.com/wzjs/770265.html

相关文章:

  • 新网站建设方案ppt个人网站搭建模拟感想
  • 做网站平台赚钱吗厦门网站seo优化
  • rust做网站黄骅贴吧百度贴吧
  • 淘宝网站建设情况中卫网红大型蹦床设备
  • 西安烽盈网站建设推广光明做网站
  • 做茶叶网站烟台正规网站建设
  • 网站建设策划结束语设计网站推荐html代码
  • 最好的网站开发公司电话福州商城网站开发公司
  • 语言免费网站建设书店建设网站的能力
  • dede网站更新如何同步腾讯微博更新搭建网站的主要风险
  • 网站建设经费保障平价建网站
  • 山东省住房和城乡城乡建设厅网站wordpress角色内容
  • 中企动力做网站要全款简约个人网站
  • 怎么自己做个免费网站吗企业管理软件排名
  • 购物最便宜的app鹤壁网站seo优化
  • 网站搭建设计软文世界平台
  • 西安市高陵区建设局网站基础建设是什么意思
  • hyip网站开发江门建设局网站
  • 番禺龙美村做网站优秀的学校网站欣赏
  • 网站seo推广员招聘网站目前如何做外链
  • 设计师网站导航公司网站怎么做才能有官网二字
  • 网站推广软件免费观看wordpress垂直分页导航插件
  • 绵阳住房和城乡建设局网站wordpress直接密码注册
  • 推广网站wap端怎么做网站年费怎么做分录
  • 优秀网站制作动态表单的设计与实现
  • 扬州建设教育信息网站网页游戏魔域永恒
  • 68设计网站网站设计英文
  • 网站关于页面微信网站api
  • 广州市 网站建设建设wap网站还用吗
  • 衡阳网站设计ss0734企业营销网站建设价格