mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
Revert "fix(setup): setup hook should be called before beforeCreate"
This reverts commit e1342df784
.
reopen #12802
close #12821
close #12822
This commit is contained in:
parent
c61395d3f1
commit
e80cd09fff
@ -1,6 +1,6 @@
|
||||
import config from '../config'
|
||||
import { initProxy } from './proxy'
|
||||
import { initProps, initState } from './state'
|
||||
import { initState } from './state'
|
||||
import { initRender } from './render'
|
||||
import { initEvents } from './events'
|
||||
import { mark, measure } from '../util/perf'
|
||||
@ -10,7 +10,6 @@ import { extend, mergeOptions, formatComponentName } from '../util/index'
|
||||
import type { Component } from 'types/component'
|
||||
import type { InternalComponentOptions } from 'types/options'
|
||||
import { EffectScope } from 'v3/reactivity/effectScope'
|
||||
import { initSetup } from '../../v3/apiSetup'
|
||||
|
||||
let uid = 0
|
||||
|
||||
@ -60,12 +59,8 @@ export function initMixin(Vue: typeof Component) {
|
||||
initLifecycle(vm)
|
||||
initEvents(vm)
|
||||
initRender(vm)
|
||||
|
||||
const opts = vm.$options
|
||||
initInjections(vm) // resolve injections before data/props
|
||||
initProps(vm, opts.props)
|
||||
initSetup(vm)
|
||||
callHook(vm, 'beforeCreate', undefined, false /* setContext */)
|
||||
initInjections(vm) // resolve injections before data/props
|
||||
initState(vm)
|
||||
initProvide(vm) // resolve provide after data/props
|
||||
callHook(vm, 'created')
|
||||
|
@ -2,6 +2,7 @@ import config from '../config'
|
||||
import Watcher from '../observer/watcher'
|
||||
import Dep, { pushTarget, popTarget } from '../observer/dep'
|
||||
import { isUpdatingChildComponent } from './lifecycle'
|
||||
import { initSetup } from 'v3/apiSetup'
|
||||
|
||||
import {
|
||||
set,
|
||||
@ -50,6 +51,11 @@ export function proxy(target: Object, sourceKey: string, key: string) {
|
||||
|
||||
export function initState(vm: Component) {
|
||||
const opts = vm.$options
|
||||
if (opts.props) initProps(vm, opts.props)
|
||||
|
||||
// Composition API
|
||||
initSetup(vm)
|
||||
|
||||
if (opts.methods) initMethods(vm, opts.methods)
|
||||
if (opts.data) {
|
||||
initData(vm)
|
||||
@ -63,8 +69,7 @@ export function initState(vm: Component) {
|
||||
}
|
||||
}
|
||||
|
||||
export function initProps(vm: Component, propsOptions: Object | undefined) {
|
||||
if (!propsOptions) return
|
||||
function initProps(vm: Component, propsOptions: Object) {
|
||||
const propsData = vm.$options.propsData || {}
|
||||
const props = (vm._props = shallowReactive({}))
|
||||
// cache prop keys so that future props updates can iterate using Array
|
||||
|
@ -263,7 +263,7 @@ describe('api: setup context', () => {
|
||||
}).$mount()
|
||||
expect(spy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
|
||||
// #12561
|
||||
it('setup props should be reactive', () => {
|
||||
const msg = ref('hi')
|
||||
@ -333,30 +333,4 @@ describe('api: setup context', () => {
|
||||
await nextTick()
|
||||
expect(_listeners.foo()).toBe(2)
|
||||
})
|
||||
|
||||
// #12802
|
||||
it('should be called before all lifecycle hooks', () => {
|
||||
const calls: string[] = []
|
||||
|
||||
Vue.mixin({
|
||||
beforeCreate() {
|
||||
calls.push('global beforeCreate')
|
||||
}
|
||||
})
|
||||
|
||||
new Vue({
|
||||
beforeCreate() {
|
||||
calls.push('component beforeCreate')
|
||||
},
|
||||
setup() {
|
||||
calls.push('setup')
|
||||
}
|
||||
})
|
||||
|
||||
expect(calls).toEqual([
|
||||
'setup',
|
||||
'global beforeCreate',
|
||||
'component beforeCreate'
|
||||
])
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user