1 .首先缓存原型上的 $ mount方法,然后在重新定义这个方法
2 .检查el,避免Vue挂载到body,html这种根节点上。
3 .如果没有定义render方法,就会把el或者template字符串转换成render方法
const mount = Vue.prototype.$mount
Vue.prototype.$mount = function (
el?: string | Element,
hydrating?: boolean
): Component {
el = el && query(el)
/* istanbul ignore if */
if (el === document.body || el === document.documentElement) {
process.env.NODE_ENV !== 'production' && warn(
`Do not mount Vue to or
- mount to normal elements instead.`)
return this
}
const options = this.$options
// resolve template/el and convert to render function
if (!options.render) {
let template = options.template
if (template) {
if (typeof temp