关于vue.js:vue中父子组件异步传递数据

应用v-if指令来动态创建子组件

子组件中:

<template>
    <div>{{value}}</div>
</template>

<script>
export default {
    props: {
        value: {
            type: String
        }
    }
}
</script>

在父组件中:

<template>
    <div>
        <div v-if="viewReady">
            <child v-bind:value=""/>
        </div>
    <div>
</template>

<script>
export default {
    data() {
        return {
            viewReady: false
        }
    },
    created() {
        this.getData()
    },
    methods: {
        getData() {
            return new Promise(r=> {
                // request
                r()
            }).then(res => {
                this.viewReady = true
            })
        }
    }
}
</script>

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理