wangyong315 / blog

0 stars 0 forks source link

如何理解Virtual DOM #7

Open wangyong315 opened 3 years ago

wangyong315 commented 3 years ago

虚拟dom

js模拟dom结构,将dom变化的对比放在js层来做。换而言之,vdom就是js对象。

<ul id="list">
<li class="item">ITEM1</li>
<li class="item">ITEM2</li>
</ul>

映射成虚拟dom就是这样

{
  tag: "ul",
  attrs: {
    id: "list"
  },
  children: {
    {
      tag: 'li',
      attrs: { className: "item" },
      children: [ "ITEM1" ]
    },
    {
      tag: 'li',
      attrs: { className: "item" },
      children: [ "ITEM2" ]
    }
  }
}