当前位置:网站首页>Form validation of uniapp
Form validation of uniapp
2022-07-07 02:52:00 【I must win this time】
Take a look back. , Usually we use element-ui How to verify the form when
<template>
<div class="">
<el-form ref="form" :rules="rules" :model="form">
<el-form-item label=" full name " prop="name">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label=" Age " prop="age">
<el-input v-model="form.age"></el-input>
</el-form-item>
</el-form>
<el-button type="primary" @click="fn"> preservation </el-button>
</div>
</template>
<script>
export default {
data() {
return {
form:{
name:'',
age:''
},
rules:{
name: [{ required: true, message: ' Required ', trigger: 'blur' }],
age: [{ required: true, message: ' Required ', trigger: 'blur' }]
}
}
},
name: '',
methods: {
fn(){
this.$refs.form.validate((result)=>{
if (result) {
console.log(' Logical processing after verification ');
}
else{
console.log(' Logical processing after verification failure ');
}
})
}
}
}
</script>
<style scoped>
</style>
(1) stay el-form Things bound on
1.ref Get form call viliadte Method to do global verification
2.:rules Validation rule
3.:model Bind associated data
(2) stay el-form-item Bind something on the
1.label Related is the title
2.prop Bindings are associated fields
(3) stay el-input Things bound on
el-input, Bind two-way bind the data to be associated
uniapp Form validation for
1.uni-forms Need to pass through rules Property passes in the agreed validation rules
<!-- rules See the complete example below for details -->
<uni-forms ref="form" :rules="rules">
...
</uni-forms>This and element-ui It's the same
2.uni-forms Need to bind model attribute , Value of the form key\value The object of composition .
<!-- formData、rules See the complete example below for details -->
<uni-forms ref="form" :model="formData" :rules="rules">
...
</uni-forms>3.uni-forms-item Need to set up name The attribute is the current field name , Field is String|Array type .
<!-- formData、rules See the complete example below for details -->
<uni-forms :modelValue="formData" :rules="rules">
<uni-forms-item label=" full name " name="name">
<uni-easyinput type="text" v-model="formData.name" placeholder=" Please enter a name " />
</uni-forms-item>
<uni-forms-item required :name="['data','hobby']" label=" Hobby ">
<uni-data-checkbox multiple v-model="formData.data.hobby" :localdata="hobby"/>
</uni-forms-item>
</uni-forms>there name amount to element-ui Inside prop
4. Rule validation
rules: {
// Yes name Field must be verified
name: {
rules: [{
required: true,
errorMessage: ' Please enter a name ',
},
{
minLength: 3,
maxLength: 5,
errorMessage: ' The length of the name is {minLength} To {maxLength} Characters ',
}
]
},
// Yes email Field must be verified
email: {
rules: [{
format: 'email',
errorMessage: ' Please enter the correct email address ',
}]
}
}
You can see it here uni One more rules.
Others can be viewed on the official website .
边栏推荐
猜你喜欢

从零安装Redis
![[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication](/img/09/b9d50f7a10e6898ac4088ee005d00b.png)
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication

The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
Django数据库(SQlite)基本入门使用教程

Redis入门完整教程:客户端管理

Five reasons for clothing enterprises to deploy MES management system

Read fast RCNN in one article

What are the characteristics of the operation and maintenance management system

ERROR: Could not find a version that satisfies the requirement xxxxx (from versions: none)解决办法

How to design interface test cases? Teach you a few tips to draft easily
随机推荐
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (initial assignment part)
牛客编程题--必刷101之双指针篇
Es6中Promise的使用
wzoi 1~200
慧通编程入门课程 - 2A闯关
换个姿势做运维!GOPS 2022 · 深圳站精彩内容抢先看!
Install redis from zero
Hash table and full comments
Mmdetection3d loads millimeter wave radar data
Redis入门完整教程:复制配置
CSDN summer camp course project analysis
S120驱动器基本调试步骤总结
数字滚动增加效果
wireshark安装
[socket] ① overview of socket technology
Redis入门完整教程:RDB持久化
记一次JAP查询导致OOM的问题分析
MySQL
MMDetection3D加载毫米波雷达数据
AWS learning notes (I)