Javascript 如何在功能组件中呈现嵌套元素?
我正在研究如何在组件中呈现多个根元素,functional component是解决方案,事情对我来说很好,但不确定如何呈现嵌套元素 请检查代码中的Javascript 如何在功能组件中呈现嵌套元素?,javascript,vue.js,vue-functional-component,Javascript,Vue.js,Vue Functional Component,我正在研究如何在组件中呈现多个根元素,functional component是解决方案,事情对我来说很好,但不确定如何呈现嵌套元素 请检查代码中的注释,我在代码中描述了对我有用的东西 export default { name: 'MyFnlComp', functional: true, render(createElement, { props }) { const itemIndex = props.item.index; const nestedEle =
注释
,我在代码中描述了对我有用的东西
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]);
createElement
的最后一个参数应该是字符串或数组
const catCard = createElement('div', {}, [nestedEle]);