05-core

Vue源码中core是Vue的核心,它实现了Vue的主体功能,是平台无关的,不论是web或是wexx都要依赖它。它的目录结构很清晰,如下

  • components
  • global-api
  • instance
  • observer
  • util
  • vdom
  • config.js
  • index.js

简单的内容在本文就直接介绍了,需要展开的内容会再单独开一篇文章来详细说明。

components

core中内置的组件 传送门

global-api

这里给Vue添加类方法 传送门

instance

这里定义了Vue构造函数,以及Vue.prototype上的方法 传送门

util

工具类 传送门

vdom

虚拟DOM 传送门

config.js

Vue的全局配置,它会影响的Vue的行为。这个配置最终会被放在Vue.config上,initGlobalAPI里面做的。

export default ({
  /**
   * Option merge strategies (used in core/util/options)
   */
  // $flow-disable-line
  optionMergeStrategies: Object.create(null),

  /**
   * Whether to suppress warnings.
   */
  silent: false,

  /**
   * Show production mode tip message on boot?
   */
  productionTip: process.env.NODE_ENV !== 'production',

  /**
   * Whether to enable devtools
   */
  devtools: process.env.NODE_ENV !== 'production',

  /**
   * Whether to record perf
   */
  performance: false,

  /**
   * Error handler for watcher errors
   */
  errorHandler: null,

  /**
   * Warn handler for watcher warns
   */
  warnHandler: null,

  /**
   * Ignore certain custom elements
   */
  ignoredElements: [],

  /**
   * Custom user key aliases for v-on
   */
  // $flow-disable-line
  keyCodes: Object.create(null),

  /**
   * Check if a tag is reserved so that it cannot be registered as a
   * component. This is platform-dependent and may be overwritten.
   */
  isReservedTag: no,

  /**
   * Check if an attribute is reserved so that it cannot be used as a component
   * prop. This is platform-dependent and may be overwritten.
   */
  isReservedAttr: no,

  /**
   * Check if a tag is an unknown element.
   * Platform-dependent.
   */
  isUnknownElement: no,

  /**
   * Get the namespace of an element
   */
  getTagNamespace: noop,

  /**
   * Parse the real tag name for the specific platform.
   */
  parsePlatformTagName: identity,

  /**
   * Check if an attribute must be bound using property, e.g. value
   * Platform-dependent.
   */
  mustUseProp: no,

  /**
   * Perform updates asynchronously. Intended to be used by Vue Test Utils
   * This will significantly reduce performance if set to false.
   */
  async: true,

  /**
   * Exposed for legacy reasons
   */
  _lifecycleHooks: LIFECYCLE_HOOKS
}: Config)

index.js

这是core的入口文件,它负责把instance提供的Vue构造函数暴露出去。

  • 引入instance提供的Vue,参考instance的内容
  • 用global-api提供的initGlobalAPI函数在Vue上添加类方法,参考global-api的内容
  • 在Vue.prototype上添加 i s S e r v e r 和 isServer和 isServerssrContext
  • 在Vue上添加FunctionalRenderContext和version

有用点赞哦,嘻嘻:)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值