@@ -14,6 +14,8 @@ import { LinkHandler } from '../decorators/link'
14
14
import { resolveComponent } from '../di'
15
15
16
16
export const GlobalStoreKey = 'GlobalStoreKey'
17
+ const hasOwnProperty = Object . prototype . hasOwnProperty
18
+ const hasOwn = ( val : any , key : string ) => hasOwnProperty . call ( val , key )
17
19
18
20
export class VueComponent < T extends { } = { } > {
19
21
/** 装饰器处理 */
@@ -34,7 +36,7 @@ export class VueComponent<T extends {} = {}> {
34
36
static defaultProps ?: any
35
37
/** vue options emits */
36
38
static emits ?: string [ ]
37
- static __vccOpts__value ?: ComponentOptions & { __vccOwner ?: any }
39
+ static __vccOpts__value ?: ComponentOptions
38
40
/** 组件option定义,vue3遇到类组件会从此属性获取组件的option */
39
41
static __vccOpts : ComponentOptions
40
42
/** 是否作为全局store提供外部入口,此时会在 当前app上注入2个方法,用于获取此组件的服务 */
@@ -130,14 +132,14 @@ Object.defineProperty(VueComponent, '__vccOpts', {
130
132
configurable : true ,
131
133
get ( ) {
132
134
const parentOpt = this . __vccOpts__value
133
- if ( parentOpt && this === parentOpt . __vccOwner ) return parentOpt
135
+ if ( parentOpt && hasOwn ( this , '__vccOpts__value' ) ) return parentOpt
134
136
const CompConstructor = this as typeof VueComponent
135
137
// eslint-disable-next-line @typescript-eslint/no-unused-vars
136
138
const { displayName, defaultProps, emits, ...rest } = CompConstructor
137
139
138
140
// 处理继承
139
141
if ( parentOpt ) {
140
- const mergeopt : ComponentOptions & { __vccOwner ?: any } = {
142
+ const mergeopt : ComponentOptions = {
141
143
...parentOpt ,
142
144
...rest ,
143
145
name : displayName || CompConstructor . name ,
@@ -148,7 +150,6 @@ Object.defineProperty(VueComponent, '__vccOpts', {
148
150
if ( CompConstructor . __vccOpts__value ! . render ) return instance
149
151
return instance . render . bind ( instance )
150
152
} ,
151
- __vccOwner : this ,
152
153
}
153
154
if ( defaultProps ) mergeopt . props = defaultProps
154
155
if ( emits ) mergeopt . emits = emits
@@ -172,7 +173,6 @@ Object.defineProperty(VueComponent, '__vccOpts', {
172
173
if ( CompConstructor . __vccOpts__value ! . render ) return instance
173
174
return instance . render . bind ( instance )
174
175
} ,
175
- __vccOwner : this ,
176
176
}
177
177
return this . __vccOpts__value
178
178
} ,
0 commit comments