antdeign vue 动态添加输入框并带校验

复制代码
<a-card style="margin-top: 24px;" :title="$t('activity.activityRule')" class="rulecard" v-if="activityData.activityType == 4">
					<a-radio-group v-model="ruleType" @change="changeRule">
						<a-radio :value="1">{{$t('activity.ladderReduce')}}</a-radio>
						<a-radio :value="2" style="margin-left: 20px">{{$t('activity.everyReduce')}}</a-radio>
					</a-radio-group>
					<a-form-model  :model="dynamicValidateForm" style="margin-top:15px" ref="dynamicValidateRef">
							<template v-if="ruleType == 2">
								<span  style="line-height:40px">{{$t('activity.everyfull')}}</span>
								<a-form-model-item  prop="domain2.value1"
								>
								<a-input-number :min="0" class="numberStyle" v-model="dynamicValidateForm.domain2.value1"/>
								</a-form-model-item>
								<span  style="line-height:40px">{{$t('activity.reduce')}}</span>
								<a-form-model-item  prop="domain2.value2" key="only"
								:rules="{
									required: true,
									message:$t('activity.notEmpty'),
									trigger: 'blur',
								}"
								>
								<a-input-number  class="numberStyle" v-model="dynamicValidateForm.domain2.value2"/>
								</a-form-model-item>
							</template>
							<template v-else>
								<template v-for="(domain, index) in dynamicValidateForm.domains" >
									<span :key="domain.index" style="line-height:40px">{{$t('activity.full')}}</span>
									<a-form-model-item :key="domain.index" :prop="'domains.' + index + '.value1'"
									:rules="{
										required: true,
										validator:checkRule1,
										trigger: 'blur',
									}"
									>
									<a-input-number :min="index == 0 ? 0 : 1" class="numberStyle" v-model="domain.value1"/>
									</a-form-model-item>
									<span :key="domain.index" style="line-height:40px">{{$t('activity.reduce')}}</span>
									<a-form-model-item :key="domain.index" :prop="'domains.' + index + '.value2'"
									:rules="{
										required: true,
										validator:checkRule2,
										trigger: 'blur',
									}"
									>
									<a-input-number class="numberStyle" v-model="domain.value2"/>
									</a-form-model-item>
									<a-icon :key="domain.index"
									v-if="dynamicValidateForm.domains.length > 1"
									type="minus-circle-o"
									class="dynamic-delete-button"
									@click="removeDomain(domain)"
									/>
									<br :key="domain.index" >
								</template>
								<a-button icon="plus" class="addBtd" style="width:380px" @click="addRule">{{$t('activity.newFullreduce')}}</a-button>
							</template>
					</a-form-model>	
					
			</a-card>

主要的坑就是 页面不显示rule校验结果,是因为要在a-form-model-item和span标签外面套个template。

相关推荐
用户新2 分钟前
V8引擎 精品漫游指南--Ignition篇(下 一) 动态执行前的事情
前端·javascript
@PHARAOH2 小时前
WHAT - GitLens vs Fork
前端
yqcoder2 小时前
前端性能优化:如何减少重绘与重排?
前端·性能优化
洋子2 小时前
Yank Note 系列 13 - 让 AI Agent 进入笔记工作流
前端·人工智能
wenzhangli75 小时前
Ooder A2UI 核心架构深度解析:WEB 拦截层的设计与实现
前端·架构
前端百草阁5 小时前
【前端性能优化全链路指南】从开发编写到构建运行的多维度实践
前端·性能优化
神探小白牙5 小时前
eCharts 多系列柱状图增加背景图
javascript·ecmascript·echarts
女生也可以敲代码5 小时前
AI时代下的50道前端开发面试题:从基础到大模型应用
前端·面试
ZhengEnCi6 小时前
M5-markconv自定义CSS样式指南 📝
前端·css·python
IT_陈寒6 小时前
SpringBoot自动配置的坑差点让我加班到天亮
前端·人工智能·后端