0👍
✅
You could use custom event
on f2 function
f2(){this.$emit('myEvent')}
Then listen to the event and fire the f1 function
<second-component v-on:myEvent="f1"></second-component>
0👍
First, dont forget the name in any component.
To communicate between components, you can use props (parent to children) or events (children to parent). See the doc here:
- Props: https://v2.vuejs.org/v2/guide/components-props.html
- Events: https://v2.vuejs.org/v2/guide/components-custom-events.html
Basically, to communicate from children to parent:
Children:
mounted() {
var returnObj = { name: 'John', id: 1241 };
this.$emit("emitToParentEvent", returnObj);
}
And in parent (first declare the component and last, in methods, add event):
<children-name @emitToParentEvent="emitToParentEvent"></children-name>
-------
methods: {
emitToParentEvent(returnObj){
//access my returnObj
}
}
Source:stackexchange.com