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