Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A strategy to validate child components with Vue and Vee Validate.
// 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