Parcourir la source

handle no content transclusion (fix #932)

Evan You il y a 11 ans
Parent
commit
7223cf377a
2 fichiers modifiés avec 14 ajouts et 4 suppressions
  1. 7 3
      src/compiler/content.js
  2. 7 1
      test/unit/specs/compiler/content_spec.js

+ 7 - 3
src/compiler/content.js

@@ -47,10 +47,14 @@ module.exports = {
   },
   },
 
 
   compile: function (content, owner, host) {
   compile: function (content, owner, host) {
-    if (owner) {
+    if (content && owner) {
       this.unlink = owner.$compile(content, host)
       this.unlink = owner.$compile(content, host)
     }
     }
-    _.replace(this.el, content)
+    if (content) {
+      _.replace(this.el, content)
+    } else {
+      _.remove(this.el)
+    }
   },
   },
 
 
   unbind: function () {
   unbind: function () {
@@ -59,4 +63,4 @@ module.exports = {
     } 
     } 
   }
   }
 
 
-}
+}

+ 7 - 1
test/unit/specs/compiler/content_spec.js

@@ -15,6 +15,12 @@ describe('Content Transclusion', function () {
     vm = new Vue(options)
     vm = new Vue(options)
   }
   }
 
 
+  it('no content', function () {
+    options.template = '<div><content></content></div>'
+    mount()
+    expect(el.firstChild.childNodes.length).toBe(0)
+  })
+
   it('default content', function () {
   it('default content', function () {
     el.innerHTML = '<p>hi</p>'
     el.innerHTML = '<p>hi</p>'
     options.template = '<div><content></content></div>'
     options.template = '<div><content></content></div>'
@@ -221,4 +227,4 @@ describe('Content Transclusion', function () {
     })
     })
   })
   })
 
 
-})
+})