当前位置:网站首页>Form组件常用校验规则-1(持续更新中~)
Form组件常用校验规则-1(持续更新中~)
2022-07-04 18:45:00 【51CTO】
前言
最近感触越来越深,就是要经常分享,分享自己遇到的坑,分享自己的解决办法,分享自己的各种经验,这非常有必要。因为,我遇到问题第一反应是先看看别人是怎么解决的,肯定有人也有相同的想法,那这个时候就需要大家都非常慷慨地分享。所以,以后我会尽量定期进行总结分享,与人方便与己方便~
参考链接
https://element.eleme.io/#/zh-CN/component/form
https://github.com/yiminghe/async-validator
表单校验简介
使用目的
在防止用户犯错的前提下,尽可能让用户更早地发现并纠正错误。
简单使用
Form 组件提供了表单验证的功能,只需要通过 rules
属性传入约定的验证规则,并将 Form-Item 的 prop
属性设置为需校验的字段名即可。
< el - form : model = "ruleForm" : rules = "rules" ref = "ruleForm" label - width = "100px" class = "demo-ruleForm" >
< el - form - item label = "活动名称" prop = "name" >
< el - input v - model = "ruleForm.name" > < /el-input>
< /el-form-item>
< el - form - item >
< el - button type = "primary" @ click = "submitForm('ruleForm')" > 立即创建 < /el-button>
< el - button @ click = "resetForm('ruleForm')" > 重置 < /el-button>
< /el-form-item>
< /el-form>
< script >
export default {
data() {
return {
ruleForm: {
name: '',
},
rules: {
name: [
{ required: true, message: '请输入活动名称', trigger: 'blur' },
{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
],
}
};
},
methods: {
submitForm( formName) {
this. $refs[ formName]. validate(( valid) => {
if ( valid) {
alert( 'submit!');
} else {
console. log( 'error submit!!');
return false;
}
});
},
resetForm( formName) {
this. $refs[ formName]. resetFields();
}
}
}
< /script>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
常用字段
required
是否为必填项,用于验证字段内容是否为空;
type
数据类型,类似数据格式校验,默认是string,常见的类型有number
,boolean
,integer
,float
,array
,date
,email
等;
pattern
字段值匹配正则表达式才能通过验证;
min
和max
对于string和数组来说,min和max表示最小和最大的长度;对于数字number来说,表示限制值大小;
trigger
触发验证的条件;
validator
可以为指定字段自定义验证函数:function(rule, value, callback);
边栏推荐
- Employment prospects of neural network Internet of things application technology [welcome to add]
- 15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
- Process of manually encrypt the mass-producing firmware and programming ESP devices
- FS4061A升压8.4V充电IC芯片和FS4061B升压12.6V充电IC芯片规格书datasheet
- Crystal optoelectronics: ar-hud products of Chang'an dark blue sl03 are supplied by the company
- Dynamic memory management
- Pytoch learning (4)
- 华为云云商店首页 Banner 资源位申请
- 1007 maximum subsequence sum (25 points) (PAT class a)
- Development and construction of DFI ecological NFT mobile mining system
猜你喜欢
【深度学习】一文看尽Pytorch之十九种损失函数
针对深度学习的“失忆症”,科学家提出基于相似性加权交错学习,登上PNAS
Regular replacement [JS, regular expression]
实践示例理解js强缓存协商缓存
Dynamic memory management
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
Small hair cat Internet of things platform construction and application model
What should we pay attention to when doing social media marketing? Here is the success secret of shopline sellers!
Abc229 summary (connected component count of the longest continuous character graph in the interval)
解密函数计算异步任务能力之「任务的状态及生命周期管理」
随机推荐
黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
【ISMB2022教程】图表示学习的精准医疗,哈佛大学Marinka Zitnik主讲,附87页ppt
做社交媒体营销应该注意些什么?Shopline卖家的成功秘笈在这里!
Niuke Xiaobai month race 7 who is the divine Archer
Niuke Xiaobai month race 7 e applese's super ability
In operation (i.e. included in) usage of SSRs filter
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
Utilisation de la barre de progression cbcggprogressdlgctrl utilisée par BCG
Huawei cloud store homepage banner resource bit application
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
Kotlin inheritance
[QNX Hypervisor 2.2用户手册]6.3.1 工厂页和控制页
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
一文搞懂Go语言中文件的读写与创建
Taishan Office Technology Lecture: about the order of background (shading and highlighting)
Multi table operation inner join query
Wireshark network packet capture
abc229 总结(区间最长连续字符 图的联通分量计数)
凌云出海记 | 文华在线&华为云:打造非洲智慧教学新方案
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient