Explorar el Código

fix transcluded inline v-repeat scope (fix #1010)

Evan You hace 11 años
padre
commit
e087e586a6
Se han modificado 2 ficheros con 33 adiciones y 1 borrados
  1. 3 1
      src/api/child.js
  2. 30 0
      test/unit/specs/element-directives/content_spec.js

+ 3 - 1
src/api/child.js

@@ -34,7 +34,9 @@ exports.$addChild = function (opts, BaseCtor) {
       )()
       ChildVue.options = BaseCtor.options
       ChildVue.linker = BaseCtor.linker
-      ChildVue.prototype = this
+      // important: transcluded inline repeaters should
+      // inherit from outer scope rather than host
+      ChildVue.prototype = opts._context || this
       ctors[BaseCtor.cid] = ChildVue
     }
   } else {

+ 30 - 0
test/unit/specs/element-directives/content_spec.js

@@ -287,6 +287,36 @@ describe('Content Transclusion', function () {
     })
   })
 
+  // #1010
+  it('v-repeat inside transcluded content', function () {
+    vm = new Vue({
+      el: el,
+      template:
+        '<testa>' +
+          '{{inner}} {{outer}}' +
+          '<div v-repeat="list"> {{inner}} {{outer}}</div>' +
+        '</testa>',
+      data: {
+        outer: 'outer',
+        inner: 'parent-inner',
+        list: [
+          { inner: 'list-inner' }
+        ]
+      },
+      components: {
+        testa: {
+          data: function () {
+            return {
+              inner: 'component-inner'
+            }
+          },
+          template: '<content></content>'
+        }
+      }
+    })
+    expect(el.textContent).toBe('parent-inner outer list-inner outer')
+  })
+
   it('single content outlet with replace: true', function () {
     vm = new Vue({
       el: el,