Home > Web Front-end > JS Tutorial > body text

Issues related to vue form validation in element

亚连
Release: 2018-06-11 10:41:20
Original
2196 people have browsed it

This article mainly introduces the solution of element combined with vue under form verification, but prompting an error when there is a value. Friends who need it can refer to it

The bound value must be the same as the value specified by the rule -------

Step one:

<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
Copy after login

Add rules ref

Part two:

<el-form-item label="活动名称" prop="name"> <el-input v-model="ruleForm.name"></el-input> </el-form-item>
Copy after login

Add prop

Part 3:

rules: {
name: [
{ required: true, message: &#39;请输入活动名称&#39;, trigger: &#39;blur&#39; },
{ min: 3, max: 5, message: &#39;长度在 3 到 5 个字符&#39;, trigger: &#39;blur&#39; }
],
resource: [
{ required: true, message: &#39;请选择活动资源&#39;, trigger: &#39;change&#39; }
],
}
Copy after login

If required is added here, there is no need to add it after the prop; for other detailed verifications here, please see the document

Part 4: Click to submit the form

(Here is a place to remember , <el-button type="primary" @click="submitForm('ruleForm')">Submit form</el-button> This must be enclosed in quotation marks, get it done

submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
Copy after login

Here is what to do after the verification is successful

} else {
console.log(&#39;error submit!!&#39;);
return false;
}
});
},
Copy after login

The above is what I compiled for everyone, I hope it will be helpful to everyone in the future.

Related articles:

How to get the specified index value with jquery

How to implement the side sliding menu in MUI

The problem of off-canvas sliding beyond the part in the mui framework

How to use better-scroll in vue2.0 to realize mobile sliding

Using cli mui in Vue related to area scrolling issues

Online paid courses in vue (detailed tutorial)

The above is the detailed content of Issues related to vue form validation in element. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template