题解 | #虚拟DOM#
虚拟DOM
https://www.nowcoder.com/practice/a283d2c284ed49468c3b0f6ec0312b0f
const _createElm = (vnode) => { vnode.tag && !vnode.text ? (vnode.tagNode = document.createElement(vnode.tag)) : (vnode.tagNode = document.createTextNode(vnode.text)); if (Object.keys(vnode.props).length) { for (const key in vnode.props) { vnode.tagNode.setAttribute(key, vnode.props[key]); } } if (vnode.children.length) { vnode.children.forEach((cnode) => { vnode.tagNode.appendChild(_createElm(cnode)); }); } return vnode.tagNode; };