0
点赞
收藏
分享

微信扫一扫

vue父组件调用子组件方法

夏木之下 2022-03-21 阅读 108

通过ref调用
子组件

<template>
  <div class="hello">
      子组件
  </div>
</template>
<script>
export default {
  name: 'Compont',
  data(){
      return{}
  },
  methods:{
      sing(){
        console.log("我是子组件方法")
      }
  }
}
</script>

父组件

<template>
  <div>
      <p>父组件</p>
      <button @click="diaoyong"> 调用子组件方法</button>
      <con ref="child"/>
  </div>
</template>

<script>
import con from '../components/componts.vue'
export default {
    name:'login',
    data(){
        return{}
    },
    methods:{
        diaoyong(){
            this.$refs.child.sing();
        } 
    },
    components:{
        con
    }

}
</script>

本文原创借鉴https://www.cnblogs.com/yuzhongyu/p/10825824.html

举报

相关推荐

0 条评论