[Vuejs]-Vue running function in child component from parent component

2👍

You can add the attribute ref and use the ref value to access the component/call its methods.

<child-component ref="child" ></child-component>


this.$refs.child.validate();

https://v2.vuejs.org/v2/guide/components.html#Child-Component-Refs

Despite the existence of props and events, sometimes you might still
need to directly access a child component in JavaScript. To achieve
this you have to assign a reference ID to the child component using
ref. For example:

var parent = new Vue({ el: ‘#parent’ }) // access child component
instance var child = parent.$refs.profile

In your case: <btn @click="$refs.child.validate()">Run child method - and validate something!</btn>

Leave a comment