当前位置:网站首页>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 .
边栏推荐
- Examples of how to use dates in Oracle
- 安全交付工程师
- Code line breaking problem of untiy text box
- Redis getting started complete tutorial: common exceptions on the client
- Summary of basic debugging steps of S120 driver
- MySQL --- 常用函数 - 字符串函数
- 慧通编程入门课程 - 2A闯关
- PSINS中19维组合导航模块sinsgps详解(滤波部分)
- Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
- Matlb| economic scheduling with energy storage, opportunity constraints and robust optimization
猜你喜欢
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (time synchronization part)
MATLB|具有储能的经济调度及机会约束和鲁棒优化
Dotconnect for DB2 Data Provider
Summary of basic debugging steps of S120 driver
如何设计好接口测试用例?教你几个小技巧,轻松稿定
进程管理基础
Redis入门完整教程:复制拓扑
Redis入门完整教程:客户端管理
Leetcode 77: combination
基于ensp防火墙双击热备二层网络规划与设计
随机推荐
Niuke programming problem -- double pointer of 101 must be brushed
惯导标定国内外研究现状小结(删减版)
Fundamentals of process management
Redis入门完整教程:复制拓扑
CDB PDB user rights management
Andrews - multimedia programming
[secretly kill little partner pytorch20 days] - [Day1] - [example of structured data modeling process]
Derivative, partial derivative, directional derivative
[leetcode]Search for a Range
NuScenes数据集关于Radar数据的统计
Leetcode 77: combination
PCL 常用拟合模型及使用方法
Lombok makes the pit of ⽤ @data and @builder at the same time
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
HAVE FUN | “飞船计划”活动最新进展
Digital scrolling increases effect
A complete tutorial for getting started with redis: RDB persistence
Have fun | latest progress of "spacecraft program" activities
MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)
写作系列之contribution