Skip to content

Vue源码 #11

@WuChuanL

Description

@WuChuanL

我在看Vue2.x源码的时候,发现文件是js文件,但是里面出现了:数据类型这种写法,我不是很懂,希望老师能讲解一下。
文件 src/core/vdom/create-element.js

export function createElement (
  context: Component,
  tag: any,
  data: any,
  children: any,
  normalizationType: any,
  alwaysNormalize: boolean
): VNode | Array<VNode> {
  if (Array.isArray(data) || isPrimitive(data)) {
    normalizationType = children
    children = data
    data = undefined
  }
  if (isTrue(alwaysNormalize)) {
    normalizationType = ALWAYS_NORMALIZE
  }
  return _createElement(context, tag, data, children, normalizationType)
}

我没有见过这种写法,这种写法为什么不会报错?为什么要这样写?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions