gpt4 book ai didi

javascript - 如何在功能组件中渲染嵌套元素?

转载 作者:行者123 更新时间:2023-12-01 00:01:37 25 4
gpt4 key购买 nike

我正在弄清楚如何在组件中渲染多个根元素,而功能组件是解决方案,一切对我来说工作正常,但只是不确定如何渲染嵌套元素。

请检查代码中的注释,其中我描述了对我有用的内容。

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]);

关于javascript - 如何在功能组件中渲染嵌套元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60685622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com