vue.js - 插槽中组件中的 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
但在工人的页面数据中并没有消失。
解决方案
推荐阅读
- javascript - 传单:获取 2 条折线相交的交点坐标
- kubernetes - 如何仅过滤来自 kubectl describe 的卷数据
命令? - protractor - 使用量角器测试 Angular Web 组件(自定义元素)
- python - GDAL 的 GetProjection() 和 GetGeoTransform() 的 Rasterio 等价物?
- python - gmsh,如何生成意外元素
- python - 如何根据分隔符将字符串拆分为多个变量
- wordpress - wp_enqueue_style 的句柄参数值来自哪里?
- java - Java(ArrayList)中的递归函数失败
- c++ - C++ 可变参数模板参数:对象不作为引用转发
- c# - 防止会话超时重置定期 ajax 调用