Uniapp 父組件調用子組件方法給子組件動態傳值


子組件

<template>
    <view class="hb-comment">
        testcontent
    </view>
</template>

<script>
    export default {
        name: 'question-comment’, //名字
        
        data() {
            return {

            }
        },
        methods: {
            likeSuccess(commentId){  //父組件要調用的方法
                console.log(8888)
                this.likeComplete(commentId);
            },
            
        }
    };
</script>

父組件

<template>
    <view>
        //ref='questionComment' 
        <question-comment ref='questionComment' @openInput="openInput"  @delComment="delComment" @preLike="preLike"  :deleteTip="'確認刪除?'"
                :cmData="commentData" v-if="commentData"></question-comment>
                
    </view>
</template>

<script>

    import questionComment from '@/components/comments/question-comment.vue'
    
    export default{
        components:{
            questionComment  //注冊子組件
        },
        computed:{
        },
        onShow(){
            
        },
        data(){
            return {
                
            }
        },
        methods:{
            async like(comment_id){
                await this.$http
                    .post(`${giveQuestionPraise}`, {
                        comment_id: comment_id
                    })
                    .then((r)=> {
                        console.log(r.data.state)
                        if(r.data.state === 2) {
                    this.$refs.questionComment.likeSuccess(comment_id); //調用子組件方法
                        }
                    });
                
            },
    }
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM