@@ -14,6 +14,8 @@ import { LinkHandler } from '../decorators/link'
1414import { resolveComponent } from '../di'
1515
1616export const GlobalStoreKey = 'GlobalStoreKey'
17+ const hasOwnProperty = Object . prototype . hasOwnProperty
18+ const hasOwn = ( val : any , key : string ) => hasOwnProperty . call ( val , key )
1719
1820export class VueComponent < T extends { } = { } > {
1921 /** 装饰器处理 */
@@ -34,7 +36,7 @@ export class VueComponent<T extends {} = {}> {
3436 static defaultProps ?: any
3537 /** vue options emits */
3638 static emits ?: string [ ]
37- static __vccOpts__value ?: ComponentOptions & { __vccOwner ?: any }
39+ static __vccOpts__value ?: ComponentOptions
3840 /** 组件option定义,vue3遇到类组件会从此属性获取组件的option */
3941 static __vccOpts : ComponentOptions
4042 /** 是否作为全局store提供外部入口,此时会在 当前app上注入2个方法,用于获取此组件的服务 */
@@ -130,14 +132,14 @@ Object.defineProperty(VueComponent, '__vccOpts', {
130132 configurable : true ,
131133 get ( ) {
132134 const parentOpt = this . __vccOpts__value
133- if ( parentOpt && this === parentOpt . __vccOwner ) return parentOpt
135+ if ( parentOpt && hasOwn ( this , '__vccOpts__value' ) ) return parentOpt
134136 const CompConstructor = this as typeof VueComponent
135137 // eslint-disable-next-line @typescript-eslint/no-unused-vars
136138 const { displayName, defaultProps, emits, ...rest } = CompConstructor
137139
138140 // 处理继承
139141 if ( parentOpt ) {
140- const mergeopt : ComponentOptions & { __vccOwner ?: any } = {
142+ const mergeopt : ComponentOptions = {
141143 ...parentOpt ,
142144 ...rest ,
143145 name : displayName || CompConstructor . name ,
@@ -148,7 +150,6 @@ Object.defineProperty(VueComponent, '__vccOpts', {
148150 if ( CompConstructor . __vccOpts__value ! . render ) return instance
149151 return instance . render . bind ( instance )
150152 } ,
151- __vccOwner : this ,
152153 }
153154 if ( defaultProps ) mergeopt . props = defaultProps
154155 if ( emits ) mergeopt . emits = emits
@@ -172,7 +173,6 @@ Object.defineProperty(VueComponent, '__vccOpts', {
172173 if ( CompConstructor . __vccOpts__value ! . render ) return instance
173174 return instance . render . bind ( instance )
174175 } ,
175- __vccOwner : this ,
176176 }
177177 return this . __vccOpts__value
178178 } ,
0 commit comments