Created
August 6, 2019 10:24
-
-
Save mach3/30bb9e141e2f78e02789c044b621eeba to your computer and use it in GitHub Desktop.
vnodeRender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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