vue源码中有一个点不懂(在createElementNS函数中):
document.createElement(namespace + ':' + tagName)
,第一次见到会带冒号的
查了一下MDN上的createElement,然后发现不能这样写:
![](https://img.haomeiwen.com/i11432478/1626a1fa3e475393.png)
不过根据这张图和下面的constructor里面的
this.ns = undefined
,貌似是要解决其他文档的兼容性的感觉
![](https://img.haomeiwen.com/i11432478/088f0c5854d75c36.png)
export default class VNode {
// 这里省略一堆属性
constructor (
tag?: string,
data?: VNodeData,
children?: ?Array<VNode>,
text?: string,
elm?: Node,
context?: Component,
componentOptions?: VNodeComponentOptions,
asyncFactory?: Function
) {
this.tag = tag
this.data = data
this.children = children
this.text = text
this.elm = elm
this.ns = undefined // constructor这里一开始把ns设置成了undefined,看起来上面的那个问题应该是为了兼容其他文档
this.context = context
this.fnContext = undefined
this.fnOptions = undefined
this.fnScopeId = undefined
this.key = data && data.key
this.componentOptions = componentOptions
this.componentInstance = undefined
this.parent = undefined
this.raw = false
this.isStatic = false
this.isRootInsert = true
this.isComment = false
this.isCloned = false
this.isOnce = false
this.asyncFactory = asyncFactory
this.asyncMeta = undefined
this.isAsyncPlaceholder = false
}
// DEPRECATED: alias for componentInstance for backwards compat.
/* istanbul ignore next */
get child (): Component | void {
return this.componentInstance
}
}
不过实际上也有一个可以指定元素名称空间的createElementNS函数, 但是vue 2.0的诞生时间可能比这个函数早, 所以需要这样写
网友评论