Skip to content

Commit be6e050

Browse files
committed
fix mounted not called for manually mounted instance with parent (fix #3898)
1 parent 86f0d11 commit be6e050

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/core/instance/lifecycle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export function lifecycleMixin (Vue: Class<Component>) {
6464
vm._update(vm._render(), hydrating)
6565
}, noop)
6666
hydrating = false
67-
// root instance, call mounted on self
68-
// mounted is called for child components in its inserted hook
69-
if (vm.$root === vm) {
67+
// manually mounted instance, call mounted on self
68+
// mounted is called for render-created child components in its inserted hook
69+
if (vm.$vnode == null) {
7070
vm._isMounted = true
7171
callHook(vm, 'mounted')
7272
}

test/unit/features/options/lifecycle.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ describe('Options lifecyce hooks', () => {
7575
expect(spy).toHaveBeenCalled()
7676
})
7777

78+
// #3898
79+
it('should call for manually mounted instance with parent', () => {
80+
const parent = new Vue()
81+
expect(spy).not.toHaveBeenCalled()
82+
new Vue({
83+
parent,
84+
template: '<div></div>',
85+
mounted () {
86+
spy()
87+
}
88+
}).$mount()
89+
expect(spy).toHaveBeenCalled()
90+
})
91+
7892
it('should mount child parent in correct order', () => {
7993
const calls = []
8094
new Vue({

0 commit comments

Comments
 (0)