1. Installation and useFirst, install it in your Vue project: npm install --save vue-input-check After the installation is complete, import and register: import inputCheck from 'vue-input-check'; // Install Vue.use(inputCheck); Then, we can use it in the form: <form autocomplete="off" novalidate> <input v-model='key' name='Input box name' v-input-check='[key,"validate-express"]'/> <!-- You can have as many input boxes as you want--> </form> As you can see, validate-express="val1:param1:param2|val2|valu3:param1" Different rules are separated by |, and the parameters of the rules that need to pass parameters are separated by :. Let’s look at a few examples: v-input-check='[key,"required|maxLength:10|regexp:^\\d{1,5}$"]' v-input-check='[key,"required"]' The following built-in rules are currently available:
2. Obtaining the Verification ResultsAfter the page rules are defined, you have two ways to get the verification results. 1.JS methodSimply use the following method to start the check: this.$validateCheck(formnode, callback, errorback); This object contains three parameters:
In addition, the error callback has a parameter with the data format: { "$el": the wrong input box node "$error": the first error message of the current input box} 2. HTML methodThe purpose of providing this method is to provide real-time feedback on the input status of the current form on the page. First, on the form, you can determine whether the form is valid by judging whether
3. Custom validation rulesIn most cases, we may also need to add new validation rules, after all, the default ones are often not enough to meet all business situations: Vue.use(inputCheck, { // Custom validation rules validate: [{ //Rule name: "XXX", // Verification method, return true for legal, false for illegal // Note that, except for el and val, the remaining parameters of this function are passed by ```:``` when used, and there can be any number of them // For example: ``` required:true|phone:parm1:param2 ``` test: function (el, val, ...) { return true|false; }, // Illegal prompt information, should return a string message: function (el, name) { return "XXX"; } }, // There can be multiple validation rules... ] }); This is the end of this article about how to implement form validation in Vue. For more relevant content about implementing form validation in Vue, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Troubleshooting MySQL high CPU load issues
>>: The process of installing and configuring nginx in win10
1. Add users and groups 1. Add mysql user group #...
Table of contents 1. Build the Vue environment 2....
mysql installer community 8.0.16.0 installation g...
This post introduces a set of free Photoshop wire...
Some people use these three tags in a perverted wa...
Table of contents 1. Get the file extension 2. Co...
1. Use Centos image to build local yum source Sin...
As shown in the figure: But when viewed under IE6...
Table of contents Implementing HTML Add CSS Imple...
Vue2+elementui's hover prompts are divided in...
Article mind map Why use master-slave replication...
Share the cool front-end page random QR code veri...
The PHP base image used in this article is: php:7...
Today, database operations are increasingly becom...
Table of contents question: There are 2 tokens in...