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上添加ssrContext
- 在Vue上添加FunctionalRenderContext和version
有用點贊哦,嘻嘻:)