uniapp里父组件控制子组件的事件

父组件控制子组件的事件

通过在父组件里给子组件一个标识,ref='自定义名称,然后在父组件方法里通过this.$refs.自定义名称.事件名进行触发控制

代码如下

父组件里

<template>
    <view> 
         <Item ref='aaa'></Item>
    </view>
</template>

<script>
    method:{
        bbb(){
             this.$refs.aaa.ccc();
       }
    }
</script>
子组件Item
<template>
    <view> 
       
    </view>
</template>

<script>
    method:{
        ccc(){
             console.log('我是子组件')
       }
    }
</script>
posted @ 2019-12-05 09:27  旧崖  阅读(4395)  评论(0编辑  收藏  举报