niaogege / niaogege.github.io

博客,记录生活,记录code
http://niaogege.cn
2 stars 1 forks source link

Vue -> Vnode 虚拟DOM #21

Open niaogege opened 6 years ago

niaogege commented 6 years ago

新的开始,希望自己能够保持足够的饥饿感! New start, I hope I can keep enough hunger!

niaogege commented 6 years ago

Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:x-requested-with,content-type,Cache-Control,Pragma,Date,x-timestamp Access-Control-Allow-Methods:POST, GET, OPTIONS Access-Control-Allow-Origin:https://juejin.im

niaogege commented 6 years ago

http://www.cnblogs.com/ypinchina/p/7827169.html
vue多文件上传进度条 进度不更新问题 https://segmentfault.com/q/1010000011845504

niaogege commented 6 years ago
niaogege commented 6 years ago

Vue 的数据更新利用的是 Object.defineProperty 的 getter setter 函数来实现的,而 Vue 默认没有对 File 对象设置 getter setter, 因此用 File 对象不会自动更新。

解决办法,就是用普通对象保存 file 对象里需要的信息,然后用来构造视图数据。或者自己手动设置 File 对象的 setter,也可以自动更新。代码如下:

niaogege commented 6 years ago

1.尽量保持语义化命名 2.保持较轻量的层级关系 3.views 页面组件,components子组件

niaogege commented 6 years ago

唯一需要注意的是,我们需要设置我们的xhr属性withCredentials为true,不然的话,cookie是带不过去的哦,设置: xhr.withCredentials = true;

niaogege commented 6 years ago

webpackChunkName拆分次数不要太多,对于个数和http请求做个权衡处理

niaogege commented 6 years ago

Vue 通过建立一个虚拟 DOM 对真实 DOM 发生的变化保持追踪。请近距离看一下这行代码:

return createElement('h1', this.blogTitle)

createElement 到底会返回什么呢?其实不是一个实际的 DOM 元素。它更准确的名字可能是 createNodeDescription,因为它所包含的信息会告诉 Vue 页面上需要渲染什么样的节点,及其子节点。我们把这样的节点描述为“虚拟节点 (Virtual Node)”,也常简写它为“VNode”。“虚拟 DOM”是我们对由 Vue 组件树建立起来的整个 VNode 树的称呼。

niaogege commented 6 years ago

如果你写了很多 render 函数,可能会觉得痛苦:

createElement(
  'anchored-heading', {
    props: {
      level: 1
    }
  }, [
    createElement('span', 'Hello'),
    ' world!'
  ]
)

特别是模板如此简单的情况下:

<anchored-heading :level="1">  
    <span>Hello</span> world!
</anchored-heading>
niaogege commented 6 years ago

children.findIndex(d => d.id === data.id);?? findIndex??