el-form动态标题和输入值,并且最后一个输入框不校验

需求:给了固定的label,叫xx单位,要输入单位的信息,但是属性名称都一样的,UI画图也是表单的形式,所以改为动态添加的形式,实现方式也很简单,循环就完事了,连着表单校验也动态

1.效果如下

2.代码实现+讲解

因为需求是最后一个单位没有必要必填,所以在rules这里判断了一下,主要就是循环遍历了el-form-item,之后prop为了区分也是用index来区分了

html 复制代码
 <el-dialog title="新建单位" :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="unitDialog" width="30%">
            <el-form
                :model="formInline"
                ref="unitRuleForm"
                label-width="130px"
                class="demo-form-inline"
                label-position="left"
            >
                <el-form-item
                    v-for="(item, index) in formInline.formData"
                    :key="index"
                    :label="item.organizations_type"
                    :prop="'formData[' + index + '].organizations_name'"
                    :rules="
                        index < formInline.formData.length - 1
                            ? {
                                  required: true,
                                  message: `${item.organizations_type}不能为空`,
                                  trigger: 'blur'
                              }
                            : null
                    "
                >
                    <el-input v-model="item.organizations_name"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="unitDialog = false">取 消</el-button>
                <el-button type="primary" @click="saveUnitData()">确 定</el-button>
            </span>
        </el-dialog>
javascript 复制代码
formInline: {
                formData: [
                    {
                        project_id: 0,
                        organizations_type: 'xx单位1',
                        organizations_name: ''
                    },
                    {
                        project_id: 0,
                        organizations_type: 'xx单位2',
                        organizations_name: ''
                    },
                    {
                        project_id: 0,
                        organizations_type: 'xx单位3',
                        organizations_name: ''
                    },
                    {
                        project_id: 0,
                        organizations_type: 'xx单位4',
                        organizations_name: ''
                    },
                    {
                        project_id: 0,
                        organizations_type: 'xx单位5',
                        organizations_name: ''
                    },
                    {
                        project_id: 0,
                        organizations_type: 'xx单位6',
                        organizations_name: ''
                    }
                ] //参建单位列表
            },

文章到此结束,希望对你有所帮助~

相关推荐
customer0825 分钟前
【开源免费】基于SpringBoot+Vue.JS个人博客系统(JAVA毕业设计)
java·vue.js·spring boot·后端·开源
乐多_L41 分钟前
使用vue3框架vue-next-admin导出表格excel(带图片)
前端·javascript·vue.js
初尘屿风1 小时前
基于微信小程序的电影院订票选座系统的设计与实现,SSM+Vue+毕业论文+开题报告+任务书+指导搭建视频
vue.js·微信小程序·小程序
南望无一1 小时前
React Native 0.70.x如何从本地安卓源码(ReactAndroid)构建
前端·react native
Mike_188702783511 小时前
1688代采下单API接口使用指南:实现商品采集与自动化下单
前端·python·自动化
customer081 小时前
【开源免费】基于SpringBoot+Vue.JS打卡健康评测系统(JAVA毕业设计)
java·vue.js·spring boot·后端·开源
鲨鱼辣椒️面1 小时前
HTML视口动画
前端·html
一小路一1 小时前
Go Web 开发基础:从入门到实战
服务器·前端·后端·面试·golang
堇舟1 小时前
HTML第一节
前端·html
纯粹要努力1 小时前
前端跨域问题及解决方案
前端·javascript·面试