Implement modern form validation to your Magento 2 VueJS forms using vuelidate
Use composer to install the module: composer require deadsimple/vuelidatelibrary
To use Vuelidate you will need to load the Vuelidate library and it's Validators using the Magento 2 requirejs methods. Select the neccesary mixin and the validators you would like to use with the destructure syntax. Load the mixin like any other mixins and start using Vuelidate as described in it's documentation.
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 }
}
})
})
This library loads: Vuelidate v0.7.5