This is a fork of lewyuburi/nuxt-validate.
If you use VeeValidate 2, can you consider to use nuxt-validate.
Nuxt.js module for validations using VeeValidate 3
Use npm
npm i vee-validate -S
npm i @mole-inc/nuxt-validate -D
or yarn
yarn add vee-validate
yarn add @mole-inc/nuxt-validate --dev
Add @mole-inc/nuxt-validate
to buildModules
.
nuxt.config.js
module.exports = {
buildModules: [
...
['@mole-inc/nuxt-validate', {
lang: 'es',
nuxti18n: {
locale: {
'zh-CN': 'zh_CN'
}
}
...
// regular vee-validate options
// https://github.com/logaretm/vee-validate/blob/master/docs/configuration.md
}]
]
}
module.exports = {
buildModules: [
'@mole-inc/nuxt-validate'
],
nuxtValidate: {
rules: ['required']
nuxti18n: {
locale: {
'zh-CN': 'zh_CN'
}
}
}
}
- Default:
undefined
The lang
option accepts the name file placed on the locale dir of Vee-Validate repository without the extension.
- Default:
undefined
If undefined
, importing all rules.
When listed from validation-rules, importing it.
rules: ['alpha_dash', 'min']
- Default:
undefined
When nuxti18n
option is set as a true
, Vee-Validate's locale changes with nuxt-i18n's locale.
If nuxt-i18n's locale and Vee-Validate's locale are different, set locale
object to convert locale code.
nuxti18n: {
locale: {
// nuxt-i18n's locale: Vee-Validate's locale
'zh-cn': 'zh_CN',
'zh-tw': 'zh_TW'
}
}
Read the official Vee-Validate documentation and demos.
We recommend using plugins.
nuxt.config.js
module.exports = {
plugins: ["~plugins/validate.js"],
}
plugins/validate.js
import { extend } from "vee-validate";
extend("my-validation", {
message: "This {_field_} is invalid.",
validate: value => {
// ...
return true;
}
});