vue ref 调用子组件的方法


定义分享子组件:share.vue;

组件内定义方法

methods:{
    toggleMask(){
        console.log('分享组件方法')
    }
}

父组件引入子组件,并声明ref:

<share 
    ref="share" 
    :contentHeight="580"
    :shareList="shareList"
></share>

父组件里面的方法通过ref执行子组件的方法

<template>
    <view>
        <view class="" @click="methodsShare">
        </view>
        <!-- 分享 -->
        <share 
            ref="share" 
            :contentHeight="580"
            :shareList="shareList"
        ></share>
    </view>
</template>

<script>
    import share from '@/components/share';
    export default {
        components: {
            share
        },
        data() {
            return {
            };
        },
        methods:{
            //分享
            methodsShare(){
                this.$refs.share.toggleMask();    
            },
        }
    }
</script>

 


免责声明!

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



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