Browse Source

use block instance when template contains only <content> with replace:true

Evan You 11 years ago
parent
commit
5e9694037c
2 changed files with 19 additions and 3 deletions
  1. 4 3
      src/compiler/transclude.js
  2. 15 0
      test/unit/specs/compiler/content_spec.js

+ 4 - 3
src/compiler/transclude.js

@@ -67,9 +67,10 @@ function transcludeTemplate (el, options) {
       if (
       if (
         frag.childNodes.length > 1 ||
         frag.childNodes.length > 1 ||
         replacer.nodeType !== 1 ||
         replacer.nodeType !== 1 ||
-        // when root node has v-repeat, the instance ends up
-        // having multiple top-level nodes, thus becoming a
-        // block instance. (#835)
+        // when root node is <content> or has v-repeat, the
+        // instance could end up having multiple top-level
+        // nodes, thus becoming a block instance.
+        replacer.tagName.toLowerCase() === 'content' ||
         replacer.hasAttribute(config.prefix + 'repeat')
         replacer.hasAttribute(config.prefix + 'repeat')
       ) {
       ) {
         return frag
         return frag

+ 15 - 0
test/unit/specs/compiler/content_spec.js

@@ -260,4 +260,19 @@ describe('Content Transclusion', function () {
     })
     })
   })
   })
 
 
+  it('single content outlet with replace: true', function () {
+    vm = new Vue({
+      el: el,
+      template:
+        '<test><p>1</p><p>2</p></test>',
+      components: {
+        test: {
+          template: '<content></content>',
+          replace: true
+        }
+      }
+    })
+    expect(el.innerHTML).toBe('<p>1</p><p>2</p>')
+  })
+
 })
 })