{"id":13465054,"url":"https://github.com/vuelidate/vuelidate","last_synced_at":"2025-12-12T03:51:03.718Z","repository":{"id":37617137,"uuid":"72931382","full_name":"vuelidate/vuelidate","owner":"vuelidate","description":"Simple, lightweight model-based validation for Vue.js","archived":false,"fork":false,"pushed_at":"2024-04-22T12:15:25.000Z","size":5370,"stargazers_count":6908,"open_issues_count":212,"forks_count":491,"subscribers_count":78,"default_branch":"next","last_synced_at":"2025-05-11T03:51:20.474Z","etag":null,"topics":["javascript","validation","vue","vuejs","vuelidate"],"latest_commit_sha":null,"homepage":"https://vuelidate-next.netlify.app/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vuelidate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["dobromir-hristov","shentao"],"ko_fi":"dobromir_hristov"}},"created_at":"2016-11-05T14:30:37.000Z","updated_at":"2025-05-09T13:58:48.000Z","dependencies_parsed_at":"2023-02-12T15:40:16.959Z","dependency_job_id":"ddef3e28-6581-4938-aad8-6f10114dddf3","html_url":"https://github.com/vuelidate/vuelidate","commit_stats":{"total_commits":569,"total_committers":90,"mean_commits":6.322222222222222,"dds":0.5852372583479789,"last_synced_commit":"b1ffaa5bcee30c33ba5332899f4392378d5f8a5a"},"previous_names":["monterail/vuelidate"],"tags_count":176,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vuelidate%2Fvuelidate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vuelidate%2Fvuelidate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vuelidate%2Fvuelidate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vuelidate%2Fvuelidate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vuelidate","download_url":"https://codeload.github.com/vuelidate/vuelidate/tar.gz/refs/heads/next","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253514570,"owners_count":21920335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","validation","vue","vuejs","vuelidate"],"created_at":"2024-07-31T14:00:56.325Z","updated_at":"2025-12-12T03:50:58.697Z","avatar_url":"https://github.com/vuelidate.png","language":"JavaScript","readme":"# vuelidate\n\n\u003e Simple, lightweight model-based validation for Vue.js 2.x \u0026 3.0\n\nVisit [Vuelidate Docs](https://vuelidate-next.netlify.app) for detailed instructions.\n\n## Sponsors\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://getform.io/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://cdn.discordapp.com/attachments/1002927810710605875/1034915542596845728/getform.png\" alt=\"Get Form\" width=\"240px\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.storyblok.com/developers?utm_source=newsletter\u0026utm_medium=logo\u0026utm_campaign=vuejs-newsletter\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://a.storyblok.com/f/51376/3856x824/fea44d52a9/colored-full.png\" alt=\"Storyblok\" width=\"240px\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.vuemastery.com/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://cdn.discordapp.com/attachments/258614093362102272/557267759130607630/Vue-Mastery-Big.png\" alt=\"Vue Mastery logo\" width=\"180px\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\nYou can use Vuelidate just by itself, but we suggest you use it along `@vuelidate/validators`, as it gives a nice collection of commonly used\nvalidators.\n\n**Vuelidate supports both Vue 3.0 and Vue 2.x**\n\n```bash\nnpm install @vuelidate/core @vuelidate/validators\n# or\nyarn add @vuelidate/core @vuelidate/validators\n```\n\n## Usage with Options API\n\nTo use Vuelidate with the Options API, you just need to return an empty Vuelidate instance from `setup`.\n\nYour validation state lives in the `data` and the rules are in `validations` function.\n\n```js\nimport { email, required } from '@vuelidate/validators'\nimport { useVuelidate } from '@vuelidate/core'\n\nexport default {\n  name: 'UsersPage',\n  data: () =\u003e ({\n    form: {\n      name: '',\n      email: ''\n    }\n  }),\n  setup: () =\u003e ({ v$: useVuelidate() }),\n  validations () {\n    return {\n      form: {\n        name: { required },\n        email: { required, email }\n      }\n    }\n  }\n}\n```\n\n## Usage with Composition API\n\nTo use Vuelidate with the Composition API, you need to provide it a state and set of validation rules, for that state.\n\nThe state can be a `reactive` object or a collection of `refs`.\n\n```js\nimport { reactive } from 'vue' // or '@vue/composition-api' in Vue 2.x\nimport { useVuelidate } from '@vuelidate/core'\nimport { email, required } from '@vuelidate/validators'\n\nexport default {\n  setup () {\n    const state = reactive({\n      name: '',\n      emailAddress: ''\n    })\n    const rules = {\n      name: { required },\n      emailAddress: { required, email }\n    }\n\n    const v$ = useVuelidate(rules, state)\n\n    return { state, v$ }\n  }\n}\n```\n\n## Providing global config to your Vuelidate instance\n\nYou can provide global configs to your Vuelidate instance using the third parameter of `useVuelidate` or by using the `validationsConfig`. These\nconfig options are used to change some core Vuelidate functionality, like `$autoDirty`, `$lazy`, `$scope` and more. Learn all about them\nin [Validation Configuration](https://vuelidate-next.netlify.app/api.html#validation-configuration).\n\n### Config with Options API\n\n```vue\n\u003cscript\u003e\nimport { useVuelidate } from '@vuelidate/core'\n\nexport default {\n  data () {\n    return { ...state }\n  },\n  validations () {\n    return { ...validations }\n  },\n  setup: () =\u003e ({ v$: useVuelidate() }),\n  validationConfig: {\n    $lazy: true,\n  }\n}\n\u003c/script\u003e\n```\n\n### Config with Composition API\n\n```js\nimport { reactive } from 'vue' // or '@vue/composition-api' in Vue 2.x\nimport { useVuelidate } from '@vuelidate/core'\nimport { email, required } from '@vuelidate/validators'\n\nexport default {\n  setup () {\n    const state = reactive({})\n    const rules = {}\n    const v$ = useVuelidate(rules, state, { $lazy: true })\n\n    return { state, v$ }\n  }\n}\n```\n\n## The validation object, aka `v$` object\n\n```ts\ninterface ValidationState {\n  $dirty: false, // validations will only run when $dirty is true\n  $touch: Function, // call to turn the $dirty state to true\n  $reset: Function, // call to turn the $dirty state to false\n  $errors: [], // contains all the current errors { $message, $params, $pending, $invalid }\n  $error: false, // true if validations have not passed\n  $invalid: false, // as above for compatibility reasons\n  // there are some other properties here, read the docs for more info\n}\n```\n\n## Validations rules are on by default\n\nValidation in Vuelidate 2 is by default on, meaning validators are called on initialisation, but an error is considered active, only after a field is dirty, so after `$touch()` is called or by using `$model`.\n\nIf you wish to make a validation lazy, meaning it only runs validations once it a field is dirty, you can pass a `{ $lazy: true }` property to\nVuelidate. This saves extra invocations for async validators as well as makes the initial validation setup a bit more performant.\n\n```js\nconst v = useVuelidate(rules, state, { $lazy: true })\n```\n\n### Resetting dirty state\n\nIf you wish to reset a form's `$dirty` state, you can do so by using the appropriately named `$reset` method. For example when closing a create/edit\nmodal, you dont want the validation state to persist.\n\n```vue\n\n\u003capp-modal @closed=\"v$.$reset()\"\u003e\n\u003c!-- some inputs  --\u003e\n\u003c/app-modal\u003e\n```\n\n## Displaying error messages\n\nThe validation state holds useful data, like the invalid state of each property validator, along with extra properties, like an error message or extra\nparameters.\n\nError messages come out of the box with the bundled validators in `@vuelidate/validators` package. You can check how change those them over at\nthe [Custom Validators page](https://vuelidate-next.netlify.app/custom_validators.html)\n\nThe easiest way to display errors is to use the form's top level `$errors` property. It is an array of validation objects, that you can iterate over.\n\n```vue\n\n\u003cp\n  v-for=\"(error, index) of v$.$errors\"\n  :key=\"index\"\n\u003e\n\u003cstrong\u003e{{ error.$validator }}\u003c/strong\u003e\n\u003csmall\u003e on property\u003c/small\u003e\n\u003cstrong\u003e{{ error.$property }}\u003c/strong\u003e\n\u003csmall\u003e says:\u003c/small\u003e\n\u003cstrong\u003e{{ error.$message }}\u003c/strong\u003e\n\u003c/p\u003e\n```\n\nYou can also check for errors on each form property:\n\n```vue\n\u003cp\n  v-for=\"(error, index) of v$.name.$errors\"\n  :key=\"index\"\n\u003e\n\u003c!-- Same as above --\u003e\n\u003c/p\u003e\n```\n\nFor more info, visit the [Vuelidate Docs](https://vuelidate-next.netlify.app).\n\n## Development\n\nTo test the package run\n\n``` bash\n# install dependencies\nyarn install\n\n# create bundles.\nyarn build\n\n# Create docs inside /docs package\nyarn dev\n\n# run unit tests for entire monorepo\nyarn test:unit\n\n# You can also run for same command per package\n```\n\n## Contributors\n\n### Current\n\n- [Damian Dulisz](https://github.com/shentao)\n- [Natalia Tepluhina](https://github.com/NataliaTepluhina)\n- [Dobromir Hristov](https://github.com/dobromir-hristov)\n\n### Emeriti\n\nHere we honor past contributors who have been a major part on this project.\n\n- [Monterail](https://github.com/monterail)\n- [Paweł Grabarz](https://github.com/Frizi)\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n","funding_links":["https://github.com/sponsors/dobromir-hristov","https://github.com/sponsors/shentao","https://ko-fi.com/dobromir_hristov"],"categories":["JavaScript","插件"],"sub_categories":["PC端"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvuelidate%2Fvuelidate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvuelidate%2Fvuelidate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvuelidate%2Fvuelidate/lists"}