Skip to content
New issue

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

关于如何自动执行 createBody #1

Open
RonkTsang opened this issue Jun 13, 2018 · 0 comments
Open

关于如何自动执行 createBody #1

RonkTsang opened this issue Jun 13, 2018 · 0 comments
Labels
小点记录 记录小的改变点、改进点

Comments

@RonkTsang
Copy link
Owner

new Vue( el: '#app')

执行 new Vue( el: '#app') 的最后一步就是:替换 #app 的 dom节点

替换通过 'appendChild' 和 ‘removeChild’ 来实现。

  • appendChild: append 的是 vue 帮我们创建的子树
  • removeChild: remove 的是 原本存在 Dom Tree 的节点

document

我们初始的 document 有一个子节点 body,这个 body 也是一个 Element ( 只是 ref 为 ‘root’,以标志为渲染树的根节点 ),也就是我们在 query 中可以返回 document.body,最后就是 document append 一个子树,因此加上 document.appendChild, document.removeChild 方法

  • document.appendChild: append 的是一个 body,但是 document 应当只有一个 body,所以此时应该是替换操作
appendChild (body) {
   if (body instanceof Element) {
     body.ref = BODY_REF
     this.body = body
     this.render()
   }
 }
  • document.removeChild: remove 了 body 的操作似乎没有意义,直接 return false

在执行 appendChild(body) 时,进行 render 的操作,进行一整颗树的渲染,(注意: 此后的更新是局部更新)

@RonkTsang RonkTsang added the 小点记录 记录小的改变点、改进点 label Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
小点记录 记录小的改变点、改进点
Projects
None yet
Development

No branches or pull requests

1 participant