当前位置:网站首页>Common verification rules of form components -1 (continuously updating ~)
Common verification rules of form components -1 (continuously updating ~)
2022-07-04 20:36:00 【51CTO】

Preface
I feel more and more deeply recently , It's about sharing often , Share your own pitfalls , Share your solutions , Share your experiences , It's very necessary . because , My first reaction when I encounter a problem is to see how others solve it , Someone must have the same idea , At this time, we all need to share very generously . therefore , In the future, I will try to summarize and share regularly , It's convenient for others and for yourself ~
Reference link
https://element.eleme.io/#/zh-CN/component/form
https://github.com/yiminghe/async-validator
Introduction to form verification
Purpose of use
On the premise of preventing users from making mistakes , Let users find and correct errors as early as possible .
Easy to use
Form Component provides the function of form validation , Just go through rules Property to pass in the validation rules of the contract , And will Form-Item Of prop Property is set to the field name to be verified .
<
el
-
form :
model
=
"ruleForm" :
rules
=
"rules"
ref
=
"ruleForm"
label
-
width
=
"100px"
class
=
"demo-ruleForm"
>
<
el
-
form
-
item
label
=
" The name of the event "
prop
=
"name"
>
<
el
-
input
v
-
model
=
"ruleForm.name"
>
<
/el-input>
<
/el-form-item>
<
el
-
form
-
item
>
<
el
-
button
type
=
"primary"
@
click
=
"submitForm('ruleForm')"
>
Create... Now
<
/el-button>
<
el
-
button
@
click
=
"resetForm('ruleForm')"
>
Reset
<
/el-button>
<
/el-form-item>
<
/el-form>
<
script
>
export
default {
data() {
return {
ruleForm: {
name:
'',
},
rules: {
name: [
{
required:
true,
message:
' Please enter the activity name ',
trigger:
'blur' },
{
min:
3,
max:
5,
message:
' The length is in 3 To 5 Characters ',
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.
Common field
required
Is it required , Used to verify whether the field content is empty ;
type
data type , Similar data format verification , The default is string, Common types are number,boolean,integer,float,array,date,email etc. ;
pattern
Only when the field value matches the regular expression can it pass the validation ;
min and max
about string And arrays ,min and max Represents the minimum and maximum length ; For numbers number Come on , Indicates the size of the limit value ;
trigger
Conditions that trigger validation ;
validator
You can customize the validation function for the specified field :function(rule, value, callback);
边栏推荐
- How is the entered query SQL statement executed?
- C # better operation mongodb database
- 更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
- Is it necessary to apply for code signing certificate for software client digital signature?
- Dark horse programmer - software testing - 09 stage 2-linux and database -31-43 instructions issued by modifying the file permission letter, - find the link to modify the file, find the file command,
- Kotlin cycle control
- B2B mall system development of electronic components: an example of enabling enterprises to build standardized purchase, sale and inventory processes
- Why is the maximum speed the speed of light
- Data set division
- YOLOv5s-ShuffleNetV2
猜你喜欢

On communication bus arbitration mechanism and network flow control from the perspective of real-time application

Related concepts of federal learning and motivation (1)
实践示例理解js强缓存协商缓存

Write it down once Net analysis of thread burst height of an industrial control data acquisition platform

Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation

Pytoch learning (4)

Flet教程之 06 TextButton基础入门(教程含源码)

【ISMB2022教程】图表示学习的精准医疗,哈佛大学Marinka Zitnik主讲,附87页ppt

Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines

Actual combat simulation │ JWT login authentication
随机推荐
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
Lingyun going to sea | Wenhua online & Huawei cloud: creating a new solution for smart teaching in Africa
Prometheus installation
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
Introduction to ACM combination counting
Abc229 summary (connected component count of the longest continuous character graph in the interval)
凌云出海记 | 文华在线&华为云:打造非洲智慧教学新方案
泰山OFFICE技术讲座:关于背景(底纹和高亮)的顺序问题
ACM组合计数入门
NLP, vision, chip What is the development direction of AI? Release of the outlook report of Qingyuan Association [download attached]
哈希(Hash)竞猜游戏系统开发功能分析及源码
Hash哈希竞猜游戏系统开发如何开发丨哈希竞猜游戏系统开发(多套案例)
[ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt
Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法
Win11共享文件打不开怎么办?Win11共享文件打不开的解决方法
What financial products can you buy with a deposit of 100000 yuan?
九齐单片机NY8B062D单按键控制4种LED状态
Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案
The problem of the maximum difference between the left and right maxima
Practical examples of node strong cache and negotiation cache