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