Method of parent component triggering child component in vue.js

First write a click event in the parent component:
inside the template:

<el-button type="primary" size="small" @click="delete">删 除</el-button>
引入子组件部分:
ref="SelfTable"是子组件在父组件中的名字
<SelfTable ref="SelfTable"/>

Methods inside:
call the method of the child component in the method of the parent component

    delete(){
     this.$refs.SelfTable.deleteService();
     // SelfTable是引入的子组件的名字,deleteService是子组件中的方法
    }

Examples:

<template>
  <div>
    <button @click="clickParent">点击</button>
    <child ref="mychild"></child>
  </div>
</template>
 
<script>
  import Child from './child';
  export default {
    name: "parent",
    components: {
      child: Child
    },
    methods: {
      clickParent() {
        this.$refs.mychild.parentHandleclick("嘿嘿嘿");
      }
    }
  }
</script>
Published 91 original articles · Like 82 · Visits 10,000+

Guess you like

Origin blog.csdn.net/qq_42893625/article/details/105054443