Categories
Vue Answers

How to call a parent component’s method within a component with Vue.js?

Spread the love

Sometimes, we want to call a parent component’s method within a component with Vue.js.

In this article, we’ll look at how to call a parent component’s method within a component with Vue.js.

How to call a parent component’s method within a component with Vue.js?

To call a parent component’s method within a component with Vue.js, we can get the parent component’s method from this.$parent.

For instance, we write

<script>
export default {
  //...
  methods: {
    someMethod() {
      this.$parent.someMethod();
    },
  },
  //...
};
</script>

to call the parent’s someMethod method with this.$parent.someMethod();.

Conclusion

To call a parent component’s method within a component with Vue.js, we can get the parent component’s method from this.$parent.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *