Przeglądaj źródła

fix runtime-only mount

Evan You 10 lat temu
rodzic
commit
76b821de0d

+ 2 - 2
src/entries/web-runtime-with-compiler.js

@@ -12,7 +12,7 @@ function idToTemplate (id) {
 }
 
 Vue.prototype.$mount = function (el) {
-  el = this.$el = el && query(el)
+  el = el && query(el)
   const options = this.$options
   // resolve template/el and convert to render function
   if (!options.render) {
@@ -42,7 +42,7 @@ Vue.prototype.$mount = function (el) {
       }
     }
   }
-  mount.call(this)
+  mount.call(this, el)
 }
 
 /**

+ 3 - 2
src/runtime/instance/lifecycle.js

@@ -1,5 +1,5 @@
 import Watcher from '../observer/watcher'
-import { warn, validateProp, remove } from '../util/index'
+import { warn, validateProp, remove, query } from '../util/index'
 import { observerState } from '../observer/index'
 import { updateListeners } from '../vdom/helpers'
 
@@ -20,7 +20,8 @@ export function initLifecycle (vm) {
 }
 
 export function lifecycleMixin (Vue) {
-  Vue.prototype.$mount = function () {
+  Vue.prototype.$mount = function (el) {
+    this.$el = el && query(el)
     if (!this.$options.render) {
       this.$options.render = () => this.$createElement('div')
       if (process.env.NODE_ENV !== 'production') {