Skip to content

Commit 7223cf3

Browse files
committed
handle no content transclusion (fix #932)
1 parent 2e40791 commit 7223cf3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/compiler/content.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ module.exports = {
4747
},
4848

4949
compile: function (content, owner, host) {
50-
if (owner) {
50+
if (content && owner) {
5151
this.unlink = owner.$compile(content, host)
5252
}
53-
_.replace(this.el, content)
53+
if (content) {
54+
_.replace(this.el, content)
55+
} else {
56+
_.remove(this.el)
57+
}
5458
},
5559

5660
unbind: function () {
@@ -59,4 +63,4 @@ module.exports = {
5963
}
6064
}
6165

62-
}
66+
}

test/unit/specs/compiler/content_spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ describe('Content Transclusion', function () {
1515
vm = new Vue(options)
1616
}
1717

18+
it('no content', function () {
19+
options.template = '<div><content></content></div>'
20+
mount()
21+
expect(el.firstChild.childNodes.length).toBe(0)
22+
})
23+
1824
it('default content', function () {
1925
el.innerHTML = '<p>hi</p>'
2026
options.template = '<div><content></content></div>'
@@ -221,4 +227,4 @@ describe('Content Transclusion', function () {
221227
})
222228
})
223229

224-
})
230+
})

0 commit comments

Comments
 (0)