File tree 2 files changed +15
-7
lines changed
2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,14 @@ import {
4
4
getVueConstructor ,
5
5
setCurrentInstance ,
6
6
getCurrentInstance ,
7
+ ComponentInternalInstance ,
7
8
} from '../runtimeContext'
8
9
import { currentVMInFn } from '../utils/helper'
9
10
10
11
const genName = ( name : string ) => `on${ name [ 0 ] . toUpperCase ( ) + name . slice ( 1 ) } `
11
12
function createLifeCycle ( lifeCyclehook : string ) {
12
- return ( callback : Function ) => {
13
- const vm = currentVMInFn ( genName ( lifeCyclehook ) )
13
+ return ( callback : Function , target ?: ComponentInternalInstance | null ) => {
14
+ const vm = currentVMInFn ( genName ( lifeCyclehook ) , target )
14
15
return (
15
16
vm && injectHookOption ( getVueConstructor ( ) , vm , lifeCyclehook , callback )
16
17
)
Original file line number Diff line number Diff line change 1
1
import Vue , { VNode , ComponentOptions , VueConstructor } from 'vue'
2
2
import { ComponentInstance } from '../component'
3
- import { getCurrentInstance , getVueConstructor } from '../runtimeContext'
3
+ import {
4
+ ComponentInternalInstance ,
5
+ getCurrentInstance ,
6
+ getVueConstructor ,
7
+ } from '../runtimeContext'
4
8
import { warn } from './utils'
5
9
6
- export function currentVMInFn ( hook : string ) : ComponentInstance | undefined {
7
- const vm = getCurrentInstance ( )
8
- if ( __DEV__ && ! vm ) {
10
+ export function currentVMInFn (
11
+ hook : string ,
12
+ target ?: ComponentInternalInstance | null
13
+ ) : ComponentInstance | undefined {
14
+ target = target || getCurrentInstance ( )
15
+ if ( __DEV__ && ! target ) {
9
16
warn (
10
17
`${ hook } is called when there is no active component instance to be ` +
11
18
`associated with. ` +
12
19
`Lifecycle injection APIs can only be used during execution of setup().`
13
20
)
14
21
}
15
- return vm ?. proxy
22
+ return target ?. proxy
16
23
}
17
24
18
25
export function defineComponentInstance < V extends Vue = Vue > (
You can’t perform that action at this time.
0 commit comments