MCPcopy
hub / github.com/ygs-code/vue / _createElement

Function _createElement

vue.js:6371–6531  ·  view source on GitHub ↗
(context,  //vm vue实例化的对象
        tag,  //节点
        data,  //标签数据,包括属性,class style 指令等
        children, //子节点
        normalizationType // 1或者2
    )

Source from the content-addressed store, hash-verified

6369
6370 //创建虚拟dom节点
6371 function _createElement(context, //vm vue实例化的对象
6372 tag, //节点
6373 data, //标签数据,包括属性,class style 指令等
6374 children, //子节点
6375 normalizationType // 1或者2
6376 ) {
6377 /**
6378 * 如果存在data.__ob__,
6379 * 说明data是被Observer观察的数据
6380 * 不能用作虚拟节点的data
6381 * 需要抛出警告,
6382 * 并返回一个空节点
6383 * 被监控的data不能被用作vnode渲染的数据的原因是:data在vnode渲染过程中可能会被改变,
6384 * 这样会触发监控,
6385 * 导致不符合预期的操作
6386 * */
6387 if (isDef(data) && isDef((data).__ob__)) {
6388 "development" !== 'production' && warn(
6389 "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" +
6390 'Always create fresh vnode data objects in each render!',
6391 context
6392 );
6393 //创建一个空的节点
6394 return createEmptyVNode()
6395 }
6396 // object syntax in v-bind
6397 // v-bind中的对象语法
6398 //如果定义有数据并且数据中的is也定义了
6399 if (isDef(data) && isDef(data.is)) {
6400 tag = data.is; //tag等于is
6401 }
6402 //如果tag不存在
6403 // 当组件的is属性被设置为一个falsy的值
6404 // Vue将不会知道要把这个组件渲染成什么
6405 // 所以渲染一个空节点
6406 if (!tag) {
6407 // in case of component :is set to falsy value
6408 //组件的情况:设置为falsy值 创建一个空节点
6409 return createEmptyVNode()
6410 }
6411 // warn against non-primitive key
6412 //警告非原始键
6413 if ("development" !== 'production' &&
6414 isDef(data) && isDef(data.key) && !isPrimitive(data.key)
6415 ) {
6416 {
6417 warn(
6418 'Avoid using non-primitive value as key, ' +
6419 'use string/number value instead.',
6420 context
6421 );
6422 }
6423 }
6424 // support single function children as default scoped slot
6425 //支持作为默认作用域插槽的单函数子函数
6426 if (
6427 Array.isArray(children) && //如果子节点是数组
6428 typeof children[0] === 'function' //并且第一个子节点类型是函数

Callers 1

createElementFunction · 0.85

Calls 9

isDefFunction · 0.85
createEmptyVNodeFunction · 0.85
isPrimitiveFunction · 0.85
normalizeChildrenFunction · 0.85
simpleNormalizeChildrenFunction · 0.85
resolveAssetFunction · 0.85
createComponentFunction · 0.85
applyNSFunction · 0.85
registerDeepBindingsFunction · 0.85

Tested by

no test coverage detected