javascript - 如何在功能组件中呈现嵌套元素?
问题描述
我正在弄清楚如何在组件中呈现多个根元素,功能组件是解决方案,对我来说一切正常,但不确定如何呈现嵌套元素。
请检查comment
我描述了什么对我有用的代码。
export default {
name: 'MyFnlComp',
functional: true,
render(createElement, { props }) {
const itemIndex = props.item.index;
const nestedEle = createElement('div', {}, 'nested element goes here');
const catCard = createElement('div', {}, nestedEle); // this doesn't work :(
const userCards = createElement('div', {}, 'Hey! this works'); // this works :)
return [catCard, userCards];
},
};
解决方案
的最后一个参数createElement
应该是字符串或数组..
const catCard = createElement('div', {}, [nestedEle]);
推荐阅读
- android - android studio 3.6 中的 Gradle 同步失败
- c - 如何编写一个以 RGB 缓冲区为输入的 gstreamer 插件?
- composer-php - Seld\JsonLint\ParsingException "/root/.composer/auth.json" 安装后不包含有效的 JSON
- c++ - C++ 中带有 Clion 的简单程序“在 '&&' 标记之前需要 `,' 或 `...'”
- jasmine - 量角器 - 茉莉花类型错误:无法读取未定义的属性“结果”
- netlogo - 在海龟的完整有向加权图中删除多个链接
- python - 使用 Selenium/Python 在 Datepicker 中更改日期
- php - 从具有不同时区的表中获取当前日期记录
- arrays - Swift - Tableview 无法通过搜索查询正确更新
- java - 我的输出只显示数组对象中的最后一个输入