当前位置:网站首页>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 .
边栏推荐
- Unity使用MaskableGraphic画一条带箭头的线
- A complete tutorial for getting started with redis: AOF persistence
- What are the applications and benefits of MES management system
- MySQL is an optimization artifact to improve the efficiency of massive data query
- Leetcode:minimum_ depth_ of_ binary_ Tree solutions
- ODBC database connection of MFC windows programming [147] (with source code)
- fasterxml ToStringSerializerBase报错
- Redis入門完整教程:問題定比特與優化
- Common fitting models and application methods of PCL
- Qpushbutton- "function refinement"
猜你喜欢
随机推荐
一本揭秘字节万台节点ClickHouse背后技术实现的白皮书来了!
PCL 常用拟合模型及使用方法
QPushButton-》函数精解
Redis入门完整教程:客户端管理
The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
[software test] the most complete interview questions and answers. I'm familiar with the full text. If I don't win the offer, I'll lose
Linear list --- circular linked list
QT common Concepts-1
Redis入门完整教程:复制配置
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (filtering part)
电气工程及其自动化
Matlb| economic scheduling with energy storage, opportunity constraints and robust optimization
CSDN 夏令营课程 项目分析
Rethinking of investment
记一次JAP查询导致OOM的问题分析
代码调试core-踩内存
Es6中Promise的使用
MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)
哈希表及完整注释
Redis入门完整教程:复制拓扑









