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。

相关推荐
LCG元35 分钟前
Vue.js组件开发-如何实现异步组件
前端·javascript·vue.js
Lorcian37 分钟前
web前端12--表单和表格
前端·css·笔记·html5·visual studio code
问道飞鱼42 分钟前
【前端知识】常用CSS样式举例
前端·css
wl85111 小时前
vue入门到实战 三
前端·javascript·vue.js
ljz20161 小时前
本地搭建deepseek-r1
前端·javascript·vue.js
爱是小小的癌1 小时前
Java-数据结构-优先级队列(堆)
java·前端·数据结构
傻小胖2 小时前
vue3中Teleport的用法以及使用场景
前端·javascript·vue.js
wl85112 小时前
Vue 入门到实战 七
前端·javascript·vue.js
Enti7c3 小时前
用 HTML、CSS 和 JavaScript 实现抽奖转盘效果
前端·css
LCG元3 小时前
Vue.js组件开发-使用Vue3如何实现上传word作为打印模版
前端·vue.js·word