父组件:

<template>
    <div>
        <child-2 ref="child2"></child-2>
        <Button type="primary" @click="chua">调方法</Button>
    </div>
</template>
<script>
import child2 from '../../components/demo3/child2.vue'
export default {
  components: { child2 },
  name: 'demo4',
  data () {
      return {

      }
  },
  methods: {
      chua () {
          console.log(this.$refs)
          debugger
          this.$refs.child2.chuachua()
      }
  }
}
</script>

子组件:

<template>
    <div @click="chuachua">子组件</div>
</template>
<script>
export default {
    name:'child2',
    props: ['chua'],
    methods: {
        chuachua () {
            alert('123')
        }
    }
}
</script>

样式展示

调用以前:父组件调用子组件中的方法

调用以后:父组件调用子组件中的方法

 

相关文章:

  • 2021-05-23
  • 2022-12-23
  • 2021-10-16
  • 2021-06-22
  • 2021-12-21
猜你喜欢
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案