Browse Source

fix slot compilation scope inside v-for (fix #1268)

Evan You 10 years ago
parent
commit
a8cb8152ee
2 changed files with 17 additions and 1 deletions
  1. 1 1
      src/directives/element/slot.js
  2. 16 0
      test/unit/specs/directives/element/slot_spec.js

+ 1 - 1
src/directives/element/slot.js

@@ -63,7 +63,7 @@ module.exports = {
   compile: function (content, context, host) {
   compile: function (content, context, host) {
     if (content && context) {
     if (content && context) {
       this.unlink = context.$compile(
       this.unlink = context.$compile(
-        content, host, this._scope, this._frag
+        content, host, this.vm._scope, this._frag
       )
       )
     }
     }
     if (content) {
     if (content) {

+ 16 - 0
test/unit/specs/directives/element/slot_spec.js

@@ -348,4 +348,20 @@ describe('Slot Distribution', function () {
     expect(el.innerHTML).toBe('hello world')
     expect(el.innerHTML).toBe('hello world')
   })
   })
 
 
+  it('inside v-for', function () {
+    var vm = new Vue({
+      el: el,
+      template: '<comp v-for="item in items">{{item.value}}</comp>',
+      data: {
+        items: [{value: 123}, {value: 234}]
+      },
+      components: {
+        comp: {
+          tempalte: '<div><slot></slot></div>'
+        }
+      }
+    })
+    expect(el.textContent).toBe('123234')
+  })
+
 })
 })