[Vuejs]-How to run function in another vue.file from their imported file

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:

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
    }
  }

Leave a comment