Просмотр исходного кода

Merge branch 'extends' into dev

Evan You 10 лет назад
Родитель
Сommit
c580a82c4e
2 измененных файлов с 7 добавлено и 5 удалено
  1. 4 2
      src/util/options.js
  2. 3 3
      test/unit/specs/util/options_spec.js

+ 4 - 2
src/util/options.js

@@ -149,7 +149,7 @@ strats.activate = function (parentVal, childVal) {
  */
 
 function mergeAssets (parentVal, childVal) {
-  var res = Object.create(parentVal)
+  var res = Object.create(parentVal || null)
   return childVal
     ? extend(res, guardArrayAssets(childVal))
     : res
@@ -333,7 +333,9 @@ export function mergeOptions (parent, child, vm) {
   var options = {}
   var key
   if (child.extends) {
-    parent = mergeOptions(parent, child.extends, vm)
+    parent = typeof child.extends === 'function'
+      ? mergeOptions(parent, child.extends.options, vm)
+      : mergeOptions(parent, child.extends, vm)
   }
   if (child.mixins) {
     for (var i = 0, l = child.mixins.length; i < l; i++) {

+ 3 - 3
test/unit/specs/util/options_spec.js

@@ -282,9 +282,9 @@ describe('Util - Option merging', function () {
     var f1 = function () {}
     var f2 = function () {}
     var f3 = function () {}
-    var componentA = { template: 'foo', methods: { f1: f1, f2: function () {} } }
-    var componentB = { extends: componentA, methods: { f2: f2 } }
-    var componentC = { extends: componentB, template: 'bar', methods: { f3: f3 } }
+    var componentA = Vue.extend({ template: 'foo', methods: { f1: f1, f2: function () {} }})
+    var componentB = { extends: componentA, methods: { f2: f2 }}
+    var componentC = { extends: componentB, template: 'bar', methods: { f3: f3 }}
     var res = merge({}, componentC)
     expect(res.template).toBe('bar')
     expect(res.methods.f1).toBe(f1)