Forked from Danilo-Araujo-Silva/Vee Validate - Validating Child components
Created
November 13, 2020 12:28
-
-
Save MaizerGomes/fbca323ae93002aaaf62273108a0f261 to your computer and use it in GitHub Desktop.
A strategy to validate child components with Vue and Vee Validate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Somewhere in the initialization: | |
| import VeeValidate from "vee-validate"; | |
| Vue.use(VeeValidate); | |
| // Then, in the parent component: | |
| export default { | |
| provide () { | |
| return { parentValidator: this.$validator } | |
| }, | |
| ... | |
| } | |
| // Then, in the child component: | |
| export default { // or `export default Vue.extend({` | |
| inject: ["parentValidator"], | |
| ... | |
| created() { | |
| this.$validator = this.parentValidator | |
| } | |
| ... | |
| } | |
| // Then, in the component to be validated (example): | |
| <v-autocomplete | |
| name="myName" | |
| v-validate="'required'" | |
| :error-messages="errors.collect('myName')" | |
| ... | |
| > | |
| </v-autocomplete> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment