Jelajahi Sumber

fix #172 `parent` option in Vue.extend

Evan You 12 tahun lalu
induk
melakukan
2ddcae6044
2 mengubah file dengan 8 tambahan dan 2 penghapusan
  1. 3 1
      src/compiler.js
  2. 5 1
      src/main.js

+ 3 - 1
src/compiler.js

@@ -576,7 +576,9 @@ CompilerProto.createBinding = function (key, directive) {
             // nested path on computed property
             compiler.defineExp(key, binding)
         } else {
-            // ensure path in data so it can be observed
+            // ensure path in data so that computed properties that
+            // access the path don't throw an error and can collect
+            // dependencies
             Observer.ensurePath(compiler.data, key)
             var parentKey = key.slice(0, key.lastIndexOf('.'))
             if (!bindings[parentKey]) {

+ 5 - 1
src/main.js

@@ -173,7 +173,11 @@ function inheritOptions (child, parent, topLevel) {
             } else {
                 child[key].push(parentVal)
             }
-        } else if (topLevel && (type === 'Object' || parentType === 'Object')) {
+        } else if (
+            topLevel &&
+            (type === 'Object' || parentType === 'Object')
+            && !(parentVal instanceof ViewModel)
+        ) {
             // merge toplevel object options
             child[key] = inheritOptions(val, parentVal)
         } else if (val === undefined) {