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。

相关推荐
木叶丸4 分钟前
跨平台方案该如何选择?
android·前端·ios
LL.。7 分钟前
同步回调和异步回调
开发语言·前端·javascript
网络点点滴11 分钟前
Vue如何处理数据、v-HTML的使用及总结
前端·vue.js·html
运维咖啡吧13 分钟前
周一才上线的网站,单单今天已经超过1000访问了
前端·程序员·ai编程
世界哪有真情16 分钟前
用虚拟IP扩容端口池:解决高并发WebSocket端口耗尽问题
前端·后端·websocket
前端世界16 分钟前
打造一个可维护、可复用的前端权限控制方案(含完整Demo)
前端
LeQi22 分钟前
当!important成为代码毒瘤:你的项目是不是也中了招?
前端·css·程序员
玲小珑23 分钟前
Next.js 教程系列(九)增量静态再生 (ISR):动态更新的静态内容
前端·next.js
Mintopia32 分钟前
B 样条曲线:计算机图形学里的 “曲线魔术师”
前端·javascript·计算机图形学
前端小巷子35 分钟前
跨域问题解决方案:CORS(跨域资源共享)
前端·网络协议·面试