我正在弄清楚如何在组件中渲染多个根元素,而功能组件是解决方案,对于我来说一切正常,但不确定如何渲染嵌套元素。
请在我描述了适用于我的代码的代码中检查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];
},
};
答案 0 :(得分:2)
createElement
的最后一个参数应该是字符串或数组..
const catCard = createElement('div', {}, [nestedEle]);