javascript - vue源码中属性旁边的?和|是什么意思
高洛峰
高洛峰 2017-04-11 12:21:24
[JavaScript讨论组]

比如下面这个里面的?和|,是es6里面的吗,可是我看es6没看到哇?

export default class VNode {
  tag: string | void;
  data: VNodeData | void;
  children: Array | void;
  text: string | void;
  elm: Node | void;
  ns: string | void;
  context: Component | void; // rendered in this component's scope
  key: string | number | void;
  componentOptions: VNodeComponentOptions | void;
  child: Component | void; // component instance
  parent: VNode | void; // compoennt placeholder node
  raw: boolean; // contains raw HTML? (server only)
  isStatic: boolean; // hoisted static node
  isRootInsert: boolean; // necessary for enter transition check
  isComment: boolean; // empty comment placeholder?
  isCloned: boolean; // is a cloned node?

  constructor (
    tag?: string,
    data?: VNodeData,
    children?: Array | void,
    text?: string,
    elm?: Node,
    ns?: string | void,
    context?: Component,
    componentOptions?: VNodeComponentOptions
  ) {
    this.tag = tag
    this.data = data
    this.children = children
    this.text = text
    this.elm = elm
    this.ns = ns
    this.context = context
    this.key = data && data.key
    this.componentOptions = componentOptions
    this.child = undefined
    this.parent = undefined
    this.raw = false
    this.isStatic = false
    this.isRootInsert = true
    this.isComment = false
    this.isCloned = false
  }
}

还有下面这种?又在后面了

type PropOptions = {
  type: Function | Array | null,
  default: any,
  required: ?boolean,
  validator: ?Function
}
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(1)
天蓬老师

这个不是es6,是flow,一个类型检查、分析工具

type: Function | Array<Function> | null,: 表示,type可能是Function,也可能是Array of Function,还可能是null

required: ?boolean,: 表示required是个可选参数,类型是boolean

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号