Home>Article>Web Front-end> About vue using validator: VeeValidate3

About vue using validator: VeeValidate3

藏色散人
藏色散人 forward
2020-09-19 16:09:09 3319browse

About vue using validator: VeeValidate3

## Recommended: "vue.js Tutorial"

Preface

I am using

vee-validateThe version is3.3.7

Installation Tutorial

cnpm install vee-validate --save

New file vee-validate.js

import { extend, ValidationObserver, ValidationProvider, localize } from 'vee-validate'import { required, email, min, between, numeric } from 'vee-validate/dist/rules'import zh_CN from 'vee-validate/dist/locale/zh_CN.json';localize('zh_cn',zh_CN) // 配置中文export default { install (Vue) { Vue.component('ValidationObserver', ValidationObserver) Vue.component('ValidationProvider', ValidationProvider) extend('required', required) extend('email', email) extend('min', min) extend('between', between) extend('numeric', numeric) extend('phone', { message: '请输入11位的手机号码', validate: value => value.length === 11 && /^1[3456789]\d{9}$/.test(value) }) }}

main .js introduce vee-validate.js

import Validate from './vee-validate'Vue.use(Validate)
The installation has been completed

Usage tutorial

New form

Display

vue使用验证器: VeeValidate3
vue使用验证器: VeeValidate3

method processing

methods:{ async checkValid () { // 是否验证通过 return this.$refs.form.validate(); }, async handleAddAddress(e){ let check = await this.checkValid(); if(! check) // 验证不通过 { let errors = Object.values(this.$refs.form.errors); let first_error_index = errors.findIndex(val => val.length >= 1); alert(errors[first_error_index][0]) } // 弹出请输入11位的手机号码 ...... }

vue使用验证器: VeeValidate3

this.$refs.form.validate()是一个promise,当然你也可以用then

Tucao

2It’s much simpler, I just want to do a simple verification.

3was inspired bylar. Personally, I find it really painful and super troublesome.

Each

inputmust be wrapped byValidationProviderto be verified.(
inputshould be encapsulated into a custom component)

The above is the detailed content of About vue using validator: VeeValidate3. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete
Previous article:None Next article:Vue中computed和method之间有什么不同点