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

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.