首页 > 解决方案 > 插槽中组件中的 Vue 渲染道具

问题描述

我有两个组件:

在第一个组件 ( FirstComponent.vue) 中,我有:

    <RightModal>
        <span slot="body">
            {{ worker }}
            <input type="checkbox" @click="selectCheckbox(worker.id)">
        </span>
    </RightModal>
    props: {
        worker: {
            type: Object,
            required: true,
        },
    },
    selectCheckbox( id ) {
        this.$root.$emit('runShowWorker', id);
    },

SecondComponent.vue我有:

    mounted() {
        this.$root.$on('runShowWorker', id => {
            showWorker(id)
            .then(res => {
                this.worker = res.data;
            })
            .catch(error => {
                console.error(error);
            });
        });
    },

我从数据库发送this.worker新数据。我使用道具发送这些数据:

SecondComponent.vue

    <FirstComponent :worker="worker" />

worker我对in有问题FirstComponent.vue。我发送了新数据,但这个道具没有渲染。我该如何解决?

编辑:

如果我尝试推送空数据:.then(res => { this.worker = null })。然后我有错误:

无效的道具:道具“工人”的类型检查失败。预期对象,得到 Null

但在工人的页面数据中并没有消失。

标签: vue.jscomponentsslotvue-props

解决方案


推荐阅读