I have a component which is passed content via a slot. I'm using a render function to output the content. The reason I'm using a render function is because I want to duplicate the content multiple times. When I use this code, everything works fine:
render(createElement){
return createElement('div', {}, this.$slots.default);
}
When I data that is being passed changes, the output changes as well.
However, since I want to duplicate the slot content, I'm now trying this:
return createElement(
'div', {},
[
createElement('div', { }, this.$slots.default),
createElement('div', { }, this.$slots.default)
]
)
Now the problem is, when the slot content changes from outside the component, only the content in the second div gets updated, the content in the first div stays the same..
Am I missing something here?
$slots.default
as the child of the element you first create and then immediately moves them again to be the child of the second created element at which point they leave the first. I don't know that Vue has a built in way to recursive clone elements in a format thatrender()
expects. – zero298$slots.default
are outside of the Vue context, you could consider the nativecloneNode
withdeep
set totrue
and see if that works. – zero298