Browse Source

fix `mounted` not called for manually mounted instance with parent (fix #3898)

dev
Evan You 8 years ago
parent
commit
be6e050b89
  1. 6
      src/core/instance/lifecycle.js
  2. 14
      test/unit/features/options/lifecycle.spec.js

6
src/core/instance/lifecycle.js

@ -64,9 +64,9 @@ export function lifecycleMixin (Vue: Class<Component>) {
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')
}

14
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: '<div></div>',
mounted () {
spy()
}
}).$mount()
expect(spy).toHaveBeenCalled()
})
it('should mount child parent in correct order', () => {
const calls = []
new Vue({

Loading…
Cancel
Save