Vue中虚拟DOM的理解 Virtual DOM是一棵以JavaScript对象作为基础的树,每一个节点称为VNode,用对象属性来描述节点,实际上它是一层对真实DOM的抽象,最终可以通过渲染操作使这
Vue中虚拟DOM的理解
<div class="root" name="root">
<p>1</p>
<div>11</div>
</div>
{
type: "tag",tagName: "div",attr: {
className: "root"
name: "root"
},parent: null,children: [{
type: "tag",tagName: "p",attr: {},parent: {} /* 父节点的引用 */,children: [{
type: "text",tagName: "text",content: "1"
}]
},{
type: "tag",content: "11"
}]
}]
}
if (typeof tag === 'string') {
let Ctor
ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag)
if (config.isReservedTag(tag)) {
// platform built-in elements
if (process.env.NODE_ENV !== 'production' && isDef(data) && isDef(data.nativeOn)) {
warn(
`The .native modifier for v-on is only valid on components but it was used on <${tag}>.`,context
)
}
vnode = new VNode(
config.parsePlatformTagName(tag),data,children,undefined,context
)
} else if ((!data || !data.pre) && isDef(Ctor = resolveAsset(context.$options,'components',tag))) {
// component
vnode = createComponent(Ctor,context,tag)
} else {
// unknown or unlisted namespaced elements
// check at runtime because it may get assigned a namespace when its
// parent normalizes children
vnode = new VNode(
tag,context
)
}
} else {
// direct component options / constructor
vnode = createComponent(tag,children)
}
https://github.com/WindrunnerMax/EveryDay
https://juejin.im/post/6844903607913938951
https://segmentfault.com/a/1190000018211084
https://github.com/lihongxun945/myblog/issues/32
https://cloud.tencent.com/developer/article/1004551
https://www.cnblogs.com/fundebug/p/vue-virtual-dom.html
https://blog.csdn.net/u010692018/article/details/78799335/