vue element-ui 通过v-for渲染的el-form-item组件,使用自带的表单验证
2024-10-10 16:53:05
HTML:
<el-form ref="newTermDetail" :model="newTermDetail" class="auto_form">
<div :style="operation =='new' ? 'margin-left: 50px' : 'margin-left: 20px'">
<el-form-item
v-for="(domain, index) in newTermDetail.questions"
:label="operation == 'new' ? ' ' : '' + domain.id"
:key="'term' + index"
:prop="'questions.' + index + '.s_question'"
:style="index == 0 ? 'margin-top: 0; margin-bottom: 20px;' : 'margin: 20px auto;'"
:rules="[{ required: true, validator: checkInputValid, message: '请输入中英文', trigger: ['blur','change'] }]">
<el-input style="width: 300px;" type="textarea" autosize v-model="domain.s_question"></el-input>
<el-button @click.prevent="removeTermDomain(domain, index)">删除</el-button>
</el-form-item>
</div>
</el-form>
js data:
data() {
let checkInput = (rules, value, callback) => {
const regex = new RegExp("^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z ]|[,、?。!,?.!])+$");
if(!regex.test(value) || !value) {
callback(new Error('请输入中英文语句'));
}else {
callback();
}
}
return {
checkInputValid: checkInput,
newTermDetail: {
questions: [
{ s_question: ''},
{ s_question: ''}
]
}
};
},
推荐网址:https://blog.csdn.net/uncle_long/article/details/80257389
最新文章
- LinkedList详细分析
- SQLserver2008如何把表格变量传递到存储过程中
- Effective C++ 2.构造 析构 赋值运算
- JavaScript对象(document对象 图片轮播)
- VBS基础篇 - wscript 对象
- java.lang.ClassFormatError: Illegal UTF8 string in constant pool in class file Server/Request
- repeater灵活运用、repeater的commmand用法、如何不用repeater展示数据
- MySql 取一天的开始时间和结束时间
- iOS 将系统文字设置为中文
- Java之数字处理类浅析
- OpenCV1.0在VC ++6.0下的配置
- 简单Spring+Struts2+Hibernate框架搭建
- CCF系列之矩阵(201512-5)
- disptch_after 自递归
- Linux系统内存占用90%以上——解决方法
- 手把手用Monkey写一个压测脚本
- 1091 N-自守数
- Hexo+Github搭建博客问题
- ThreadPoolExecutor简单学习
- spark shell学习笔记
热门文章
- 33 Python 详解命令解析 - argparse--更加详细--转载
- 获取IP及判断IP是否在区间
- 将.db文件导入SQLServer2008数据库
- [转]fatal error LNK1112: 模块计算机类型“X86”与目标计算机类型“x64”冲突
- Android JNI 传递对象
- java web 方面
- cyberduck的SSH登录
- Lua --- 输入一个数字,输出阶乘
- 第 3 章 镜像 - 020 - 搭建本地 Registry
- value,text,attr等区别