Evan You 10 лет назад
Родитель
Сommit
4d508dcbfa

+ 23 - 0
src/runtime/instance/lifecycle.js

@@ -1,3 +1,6 @@
+import Watcher from '../observer/watcher'
+import { query, toArray } from '../util/index'
+
 export function callHook (vm, hook) {
   vm.$emit('pre-hook:' + hook)
   var handlers = vm.$options[hook]
@@ -25,6 +28,26 @@ export function initLifecycle (vm) {
 }
 
 export function lifecycleMixin (Vue) {
+  Vue.prototype.$mount = function (el) {
+    callHook(this, 'beforeMount')
+    el = this.$el = el && query(el)
+    if (el) {
+      // clean element
+      el.innerHTML = ''
+      if (el.hasAttributes()) {
+        const attrs = toArray(el.attributes)
+        for (let i = 0; i < attrs.length; i++) {
+          el.removeAttribute(attrs[i].name)
+        }
+      }
+    }
+    this._watcher = new Watcher(this, this._render, this._update)
+    this._update(this._watcher.value)
+    callHook(this, 'mounted')
+    this._mounted = true
+    return this
+  }
+
   Vue.prototype.$destroy = function () {
     if (this._isDestroyed) {
       return

+ 1 - 22
src/runtime/instance/render.js

@@ -1,5 +1,4 @@
-import Watcher from '../observer/watcher'
-import { extend, query, resolveAsset, hasOwn, isArray, isObject } from '../util/index'
+import { extend, resolveAsset, hasOwn, isArray, isObject } from '../util/index'
 import { createElement, patch, updateListeners, flatten } from '../vdom/index'
 import { callHook } from './lifecycle'
 import { getPropValue } from './state'
@@ -97,26 +96,6 @@ export function renderMixin (Vue) {
     return vnode
   }
 
-  Vue.prototype.$mount = function (el) {
-    callHook(this, 'beforeMount')
-    el = this.$el = el && query(el)
-    if (el) {
-      // clean element
-      el.innerHTML = ''
-      if (el.hasAttributes()) {
-        const attrs = el.attributes
-        for (let i = 0, l = attrs.length; i < l; i++) {
-          el.removeAttribute(attrs[i].name)
-        }
-      }
-    }
-    this._watcher = new Watcher(this, this._render, this._update)
-    this._update(this._watcher.value)
-    callHook(this, 'mounted')
-    this._mounted = true
-    return this
-  }
-
   Vue.prototype.$forceUpdate = function () {
     this._watcher.update()
   }

+ 1 - 1
src/runtime/vdom/create-element.js

@@ -26,7 +26,7 @@ export default function createElement (tag, data, children) {
           'make sure to provide the "name" option.'
         )
       }
-      return VNode(tag, data, flatten(children()))
+      return VNode(tag, data, flatten(children && children()))
     }
   } else {
     return Component(tag, data, parent, children)