VueJs – How to call a method from non-parent-child component in vue-js

call method from non parent child component

If you have an idea about the vue js then you know that how we can pass variables or methods in Vue js , basically we use the props to do such activity, but what if there is no parent-child relation in the component, and you can want to call those methods.

Let’s suppose I have two components, one name is ComponentOne.vue and another as ComponentTwo.vue, and I want to call componentOne.vue method from ComponentTwo.vue.

ComponentOne.vue Code

created() {

  //at the place of componentOne you can write your component name
  this.$root.$refs.ComponentOne = this

methods: {
  test() {
    console.log('Hello Codehunger')

ComponentTwo.vue Code


That’s it this is how you can call a component method when there is no parent-child relation

5 1 vote
Article Rating

Do you want to hire us for your Project Work? Then Contact US.
Spread the love
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x