Vue
by simati
HTML
<div id="app">
<test>
{{someValue}}
</test>
</div>
Vue
function deepClone(vnodes, createElement) {
function cloneVNode (vnode) {
const clonedChildren = vnode.children && vnode.children.map(vnode => cloneVNode(vnode));
const cloned = createElement(vnode.tag, vnode.data, clonedChildren);
cloned.text = vnode.text;
cloned.isComment = vnode.isComment;
cloned.componentOptions = vnode.componentOptions;
cloned.elm = vnode.elm;
cloned.context = vnode.context;
cloned.ns = vnode.ns;
cloned.isStatic = vnode.isStatic;
cloned.key = vnode.key;
return cloned;
}
const clonedVNodes = vnodes.map(vnode => cloneVNode(vnode))
return clonedVNodes;
}
Vue.component('test', {
render(createElement){
console.log(this.$slots.default);
return createElement(
'div', {},
[
createElement('div', { }, this.$slots.default),
createElement('div', { }, [...deepClone(this.$slots.default, createElement)])
]
)
}
})
new Vue({
el: "#app",
data: {
someValue: Math.random()
},
mounted() {
setInterval(()=>{
this.someValue = Math.random()
},1000);
}
})