We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TODO 正在热火朝天更新中,欢迎催更~
虚拟节点vnode:
vnode = { "tag": "div", "children": [ { "text": "hi, Vue.js" } ], }
渲染出真实DOM HTML:
<div>hi, Vue.js</div>
vm.patch(vm.$el, vnode)
emptyNodeAt(elm)
nodeOps.createElement(tag, vnode)
vnode.elm
children
this.createElm()
document.createTextNode(text)
insert(parentElm, vnode.elm, refElm);
body
parentNode.insertBefore
node.appendChild(child)
this.removeVnodes(oldVnode)
node.removeChild(child);
The text was updated successfully, but these errors were encountered:
No branches or pull requests
DEMO:https://jsbin.com/lekajaw/edit?html,output
TODO 正在热火朝天更新中,欢迎催更~
核心原理
虚拟节点vnode:
渲染出真实DOM HTML:
vm.patch(vm.$el, vnode)
方法,传入旧节点和新节点作为参数。第一次渲染的旧节点是一个空的虚拟节点:emptyNodeAt(elm)
。nodeOps.createElement(tag, vnode)
,基于tag等属性,将虚拟节点转化为真实DOM,赋值给vnode.elm
。children
属性中的子元素,进行遍历,对每个子元素调用this.createElm()
递归生成真实DOM,底层基于document.createTextNode(text)
等原生DOM API实现。insert(parentElm, vnode.elm, refElm);
,将生成的子元素真实DOM树,插入到父元素中;将新节点完整的真实DOM树,插入到body
元素中。底层基于parentNode.insertBefore
,node.appendChild(child)
等原生DOM API实现。this.removeVnodes(oldVnode)
,删除旧节点对应的真实DOM,基于原生DOM API:node.removeChild(child);
实现。The text was updated successfully, but these errors were encountered: