vue2 父组件调用子组件的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wuyan1001/article/details/82220479

vue2.0里面父组件调用子组件的方法是通过$refs实现的。

//子组件
export default{
    methods:{
        getDealer:function(value){
            console.log(value);
            console.log('这是子组件方法');
        }
    }
}
//父组件
<template>
    <myChild ref="child"></myChild>
</template>

export default{
    import myChild from '@/components/myChild'
    export default{
        components:{
            myChild
        },
        mounted:{
            //调用子组件方法
           this.$refs.child.getDealer(val)  //通过$refs找到子组件,并找到方法执行
        }
    }
}

猜你喜欢

转载自blog.csdn.net/wuyan1001/article/details/82220479