Skip to content

Commit

Permalink
fix(runtime-core): fix user attched public instance properties that s…
Browse files Browse the repository at this point in the history
…tart with "$"
  • Loading branch information
yyx990803 committed Apr 17, 2020
1 parent 99fd158 commit d7ca1c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/runtime-core/__tests__/componentProxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ describe('component: proxy', () => {
instanceProxy.foo = 1
expect(instanceProxy.foo).toBe(1)
expect(instance!.ctx.foo).toBe(1)

// should also allow properties that start with $
const obj = (instanceProxy.$store = {})
expect(instanceProxy.$store).toBe(obj)
expect(instance!.ctx.$store).toBe(obj)
})

test('globalProperties', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime-core/src/componentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
(cssModule = cssModule[key])
) {
return cssModule
} else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
// user may set custom properties to `this` that start with `$`
accessCache![key] = AccessTypes.CONTEXT
return ctx[key]
} else if (
// global properties
((globalProperties = appContext.config.globalProperties),
Expand Down

0 comments on commit d7ca1c5

Please sign in to comment.