如官方 platforms
中的示例一样,在从 core 导出 Vue 核心代码后,还要再经过平台的加工,比如 weex
// install platform specific utils
Vue.config.mustUseProp = mustUseProp
Vue.config.isReservedTag = isReservedTag
Vue.config.isRuntimeComponent = isRuntimeComponent
Vue.config.isUnknownElement = isUnknownElement
// install platform runtime directives and components
Vue.options.directives = platformDirectives
Vue.options.components = platformComponents
// install platform patch function
Vue.prototype.__patch__ = patch
// wrap mount
Vue.prototype.$mount = function (
el?: any,
hydrating?: boolean
): Component {
return mountComponent(
this,
el && query(el, this.$document),
hydrating
)
}
- 将
config
中与平台相关的内容重新配置 - 添加平台特有的公共
options
- 将
__patch__
改为平台的 patch 函数 - 安装平台的
$mount
函数
除去 core 部分是多平台通用的,其他都需要平台专门编写,最主要的就是与真实视图相关联的那一层,比如 $mount
、patch
等