Skip to content

Instantly share code, notes, and snippets.

@mach3
Created August 6, 2019 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mach3/30bb9e141e2f78e02789c044b621eeba to your computer and use it in GitHub Desktop.
Save mach3/30bb9e141e2f78e02789c044b621eeba to your computer and use it in GitHub Desktop.
vnodeRender
export const vnodeRender = {
methods: {
vnodeRender(vnode) {
if (process.browser) {
if (!vnode.tag) {
return document.createTextNode(vnode.text)
}
const el = document.createElement(vnode.tag)
if (vnode.data) {
if (vnode.data.staticClass) {
el.setAttribute('class', vnode.data.staticClass)
}
if (vnode.data.attrs) {
Object.keys(vnode.data.attrs)
.forEach((key) => {
el.setAttribute(key, vnode.data.attrs[key])
})
}
}
if (vnode.children) {
vnode.children.forEach((child) => {
el.appendChild(this.vnodeRender(child))
})
}
return el
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment