[Vuejs]-Call a component method from other component

0👍

I think a good solution would be to use a Mixin. You can do a global Mixin as follows.

Vue.mixin({
  methods: {
     async fetchData() {
       const playlists = await api.getAllPlaylists();
     }
  }
});

Put this before your main Vue instance and it will be available to any of your components.

If you don’t want it to be available globally define it as below.

var fetchData = {
  methods: {
     async fetchData() {
       const playlists = await api.getAllPlaylists();
     }
  }
}

Then include it in your component definitions

  export default {
     mixins: [fetchData],
     data(){
        //...
     }
  }

More on Mixins https://v2.vuejs.org/v2/guide/mixins.html

Leave a comment