vue父组件点击事件调用子组件方法


第一步:

在子组件注册一个方法

比如

showSure(){
            this.show=true
            console.log('成功调用子组件方法')
 },
 
然后再父组件中
 <button @click="getChild">点击调用子组件</button>3

 <!-- 子组件注册个ref -->
  <toast ref="child1"></toast>
 

<script>
import toast from './toast'//引入子组件
export default {
    components:{toast},//注册组件
    name:'login',
    methods:{
        getChild(){
            this.$refs.child1.showSure() //child1是写在子组件上的属性 showSure()是子组件的方法名

            
        }
    }
}
</script>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM