vue.js - Vue:功能组件不接收道具
问题描述
该组件smart-list
完成了它的工作并呈现了正确的组件。它只是不传递道具。我希望他们在 acontext.data
但它是undefined
。
SmartList.vue
import EmptyList from "./EmptyList";
import FullList from "./FullList";
export default {
functional: true,
props: {
items: {
type: Array
}
},
render(h, { props, data, children }) {
if (props.items.length > 0) {
return h(FullList, data, children);
} else {
return h(EmptyList, data, children);
}
}
};
我准备了一个codeandbox示例
我想念什么?
解决方案
我找到了解决方案。在smart-list
组件中,我更改了一行:
import EmptyList from "./EmptyList";
import FullList from "./FullList";
export default {
functional: true,
props: {
items: {
type: Array
}
},
render(h, { props, data, children }) {
if (props.items.length > 0) {
- return h(FullList, data, children);
+ return h(FullList, { attrs: props }, children);
} else {
return h(EmptyList, data, children);
}
}
};
现在它起作用了。有人能指出我为什么传递完整的data
对象不起作用吗?
推荐阅读
- c - 在不断将数据写入文件(SDCard)时,应该多久打开和关闭一次文件?
- java - Java jar 文件无法识别从 gradle 添加的外部库
- delphi - 从 COM 指针到记录 / 如何执行(dotNet 的)Marshal.PtrToStructure 的 Delphi 版本
- reactjs - useFetch Can't perform a React state update on an unmounted component 警告
- reactjs - 去抖动 async/await 并更新组件状态
- asp.net-mvc - 客户端不显眼的验证未按预期工作
- javascript - 等待脚本在 VueJS 中加载?
- php - 如何在不运行 Composer 的情况下在 Google App Engine 上部署 php 应用程序?
- r - R中的字符串格式解析
- c# - 如何仅屏蔽/强制使用名字和姓氏字母的大小写