Can events in the vue parent component be hung directly on the child component?

for example, I pass a method in the parent component, but what should I do if it is executed in the child component? Do not use $emit

Nov.02,2021

There are many

methods. The more common one is to define a Function parameter in the porps of the child component, and the parent component passes the method as a parameter

.

subcomponent code snippet

export default {
  name: 'Children',
  props: {
    parentMethod: Function,
  },
  methods: {
    onClick() {
      this.parentMethod();
    },

parent component code snippet

<template>
  <children :parent-method="testMethod"></children>
</template>
<script>
  export default {
    methods: {
      testMethod() {
        console.log('test');
      },

in this way, when the child component triggers onClick , the parent component's testMethod is called. Although the process is not as clear as $on + $emit , it is still very maintainable

.

ide-inject" rel=" nofollow noreferrer "> provide-inject

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9fdd8-1a8c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9fdd8-1a8c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?