deadsimple/vuelidatelibrary

一个简单的模块,用于在您的现代 Magento 2 Vue 项目中使用 Vuelidate

安装次数: 3,948

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

语言:JavaScript

类型:magento2-module

1.0.2 2020-09-30 13:03 UTC

This package is auto-updated.

Last update: 2024-09-29 05:36:24 UTC


README

Latest Stable Version Total Downloads License

Deadsimple Vuelidate Magento2 Composer Library

使用 vuelidate 在您的 Magento 2 VueJS 表单中实现现代表单验证

安装

使用 composer 安装模块: composer require deadsimple/vuelidatelibrary

使用方法

要使用 Vuelidate,您需要使用 Magento 2 requirejs 方法加载 Vuelidate 库及其 Validators。选择必要的混入和您想要使用的验证器,并使用解构语法。像其他混入一样加载混入,然后按照其 文档 中所述使用 Vuelidate。

define([
    'Vue',
    'Vuelidate',
    'VuelidateValidators',
], function (Vue, Vuelidate, validators) {

    const {validationMixin} = Vuelidate;
    const {required, email } = validators;
    
    Vue.component('contactForm', {
        template: template,
        mixins: [ validationMixin ],
        data() {
          return { 
            name: null,
            email: null, 
          }
        },
        validations(){ 
          name: { required },
          email: { required, email }
        }
    })
})

版本

此库加载: Vuelidate v0.7.5