File tree 2 files changed +30
-11
lines changed
packages/runtime-core/src
2 files changed +30
-11
lines changed Original file line number Diff line number Diff line change @@ -417,12 +417,14 @@ export function applyOptions(
417
417
for ( const key in rawData ) {
418
418
checkDuplicateProperties ! ( OptionTypes . DATA , key )
419
419
// expose data on ctx during dev
420
- Object . defineProperty ( ctx , key , {
421
- configurable : true ,
422
- enumerable : true ,
423
- get : ( ) => rawData [ key ] ,
424
- set : NOOP
425
- } )
420
+ if ( key [ 0 ] !== '$' && key [ 0 ] !== '_' ) {
421
+ Object . defineProperty ( ctx , key , {
422
+ configurable : true ,
423
+ enumerable : true ,
424
+ get : ( ) => rawData [ key ] ,
425
+ set : NOOP
426
+ } )
427
+ }
426
428
}
427
429
}
428
430
}
Original file line number Diff line number Diff line change @@ -195,10 +195,19 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
195
195
) {
196
196
return globalProperties [ key ]
197
197
} else if ( __DEV__ && currentRenderingInstance ) {
198
- warn (
199
- `Property ${ JSON . stringify ( key ) } was accessed during render ` +
200
- `but is not defined on instance.`
201
- )
198
+ if ( data !== EMPTY_OBJ && key [ 0 ] === '$' && hasOwn ( data , key ) ) {
199
+ warn (
200
+ `Property ${ JSON . stringify (
201
+ key
202
+ ) } must be accessed via $data because it starts with a reserved ` +
203
+ `character and is not proxied on the render context.`
204
+ )
205
+ } else {
206
+ warn (
207
+ `Property ${ JSON . stringify ( key ) } was accessed during render ` +
208
+ `but is not defined on instance.`
209
+ )
210
+ }
202
211
}
203
212
} ,
204
213
@@ -280,7 +289,15 @@ export const RuntimeCompiledPublicInstanceProxyHandlers = {
280
289
return PublicInstanceProxyHandlers . get ! ( target , key , target )
281
290
} ,
282
291
has ( _ : ComponentRenderContext , key : string ) {
283
- return key [ 0 ] !== '_' && ! isGloballyWhitelisted ( key )
292
+ const has = key [ 0 ] !== '_' && ! isGloballyWhitelisted ( key )
293
+ if ( __DEV__ && ! has && PublicInstanceProxyHandlers . has ! ( _ , key ) ) {
294
+ warn (
295
+ `Property ${ JSON . stringify (
296
+ key
297
+ ) } should not start with _ which is a reserved prefix for Vue internals.`
298
+ )
299
+ }
300
+ return has
284
301
}
285
302
}
286
303
You can’t perform that action at this time.
0 commit comments