Skip to content

Commit ca30122

Browse files
committed
allow $mount() to auto-create a div when called with no arguments
1 parent 0cefbbb commit ca30122

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/api/lifecycle.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ exports.$mount = function (el) {
1515
_.warn('$mount() should be called only once.')
1616
return
1717
}
18-
if (typeof el === 'string') {
18+
if (!el) {
19+
el = document.createElement('div')
20+
} else if (typeof el === 'string') {
1921
var selector = el
2022
el = document.querySelector(el)
2123
if (!el) {

test/unit/specs/api/lifecycle_spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ if (_.inBrowser) {
2828
expect(el.textContent).toBe('hi!')
2929
})
3030

31+
it('auto-create', function () {
32+
var vm = new Vue({
33+
template: '{{a}}',
34+
data: {
35+
a: 123
36+
}
37+
})
38+
vm.$mount()
39+
expect(vm.$el).toBeTruthy()
40+
expect(vm.$el.tagName).toBe('DIV')
41+
expect(vm.$el.textContent).toBe('123')
42+
})
43+
3144
it('selector', function () {
3245
el.id = 'mount-test'
3346
document.body.appendChild(el)

0 commit comments

Comments
 (0)