diff --git a/src/core/instance/lifecycle.js b/src/core/instance/lifecycle.js index fcd3f75a..f7700892 100644 --- a/src/core/instance/lifecycle.js +++ b/src/core/instance/lifecycle.js @@ -64,9 +64,9 @@ export function lifecycleMixin (Vue: Class) { vm._update(vm._render(), hydrating) }, noop) hydrating = false - // root instance, call mounted on self - // mounted is called for child components in its inserted hook - if (vm.$root === vm) { + // manually mounted instance, call mounted on self + // mounted is called for render-created child components in its inserted hook + if (vm.$vnode == null) { vm._isMounted = true callHook(vm, 'mounted') } diff --git a/test/unit/features/options/lifecycle.spec.js b/test/unit/features/options/lifecycle.spec.js index 87a623a6..b6ffe541 100644 --- a/test/unit/features/options/lifecycle.spec.js +++ b/test/unit/features/options/lifecycle.spec.js @@ -75,6 +75,20 @@ describe('Options lifecyce hooks', () => { expect(spy).toHaveBeenCalled() }) + // #3898 + it('should call for manually mounted instance with parent', () => { + const parent = new Vue() + expect(spy).not.toHaveBeenCalled() + new Vue({ + parent, + template: '
', + mounted () { + spy() + } + }).$mount() + expect(spy).toHaveBeenCalled() + }) + it('should mount child parent in correct order', () => { const calls = [] new Vue({