简体   繁体   English

如何在功能组件中呈现嵌套元素?

[英]How to render nested element in functional component?

I am figuring out how to render multiple root elements in component and functional component is the solution, things are working fine for me but just not sure how to render nested element.我正在弄清楚如何在组件中呈现多个根元素,而功能组件是解决方案,对我来说一切正常,但不确定如何呈现嵌套元素。

Please check comment in the code where I have described what's working for me.请检查代码中的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]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM