I'm currently working on constructing a custom component using a render function.
The component being rendered can receive an unlimited number of slots. For instance, in the following example there are three available slots (named element_1
, element_2
, element_3
).
The code snippet below utilizing Array.reduce()
is intended to achieve the same as:
scopedSlots: {
"element_1": () => createElement('div', 'hello world'),
"element_2": () => createElement('div', 'hello world'),
"element_3": () => createElement('div', 'hello world'),
}
This is a simplified version using Array.reduce()
:
const records = [
{
"index": 1,
},
{
"index": 2,
},
{
"index": 3,
}
]
render: function (createElement) {
return createElement("replicator-component", {
attrs: { elements: records.length},
scopedSlots: records.reduce((a,x) => ({...a,
['element_' + x.index]:
() => { createElement( 'div', 'hello world') }}), {})
});
},
Despite implementing this logic, nothing appears on the screen and no error messages are provided. Does anyone have any suggestions?