I am through $emit method, the implementation of child component call parent component method. In the course of a project, there have been cases where clicking on a child component wants to call the parent component’s methods. You can use the following methods for reference.

Parent component code section:

<template> <div> <child @fatherMethod="fatherMethod"></child> </div> </template> <script> import child from '~/components/dam/child'; export default { components: { child }, methods: { fatherMethod() { console.log('123456test'); }}}; </script>Copy the code

Sub-component code section:

<template> <div> < button@click ="childMethod()"> click </button> </div> </template> <script> export default {methods: { childMethod() { this.$emit('fatherMethod'); }}}; </script>Copy the code