Vue2.6.x源码阅读 - 4.源码阅读-platform
Vue Web端入口
// src/platform/web/runtime/index.js // import 部分 import Vue from 'core/index' // core封装导出的Vue // ... // 挂载浏览器模式下的专用方法,对于开发者无用 // install platform specific utils Vue.config.mustUseProp = mustUseProp Vue.config.isReservedTag = isReservedTag Vue.config.isReservedAttr = isReservedAttr Vue.config.getTagNamespace = getTagNamespace Vue.config.isUnknownElement = isUnknownElement // 在option中挂载指令与组件 // install platform runtime directives & components extend(Vue.options.directives, platformDirectives) extend(Vue.options.components, platformComponents) // ⭐️使用 虚拟DOM 更新 真实浏览器DOM 的核心算法 // install platform patch function Vue.prototype.__patch__ = inBrowser ? patch : noop // 非浏览器下不作操作,noop来自于上文中的util.js,等价于no operation // 挂载在Vue实例上的最原始的 $mount 方法,用于调用挂载组件的方法 Vue.prototype.$mount = function ( el?: string | Element, hydrating?: boolean ): Component { // 获取元素并调用 mountComponent 方法 el = el && inBrowser ? query(el) : undefined return mountComponent(this, el, hydrating) } // 再往下的部分则为使用 vue-devtool 插件时才需要的逻辑,可以暂时不作考虑 // devtools global hook /* istanbul ignore next */ if (inBrowser) { // ... } export default Vue
runtime vs runtime-with-compiler
最后更新于