]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix user attched public instance properties that start with "$"
authorEvan You <yyx990803@gmail.com>
Fri, 17 Apr 2020 14:23:10 +0000 (10:23 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 17 Apr 2020 14:23:10 +0000 (10:23 -0400)
packages/runtime-core/__tests__/componentProxy.spec.ts
packages/runtime-core/src/componentProxy.ts

index d5d46c25eeeac61fddf4983dda1168970030e41f..706fad4a69a8ab697bbe9f532f8fb98edc07ac67 100644 (file)
@@ -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', () => {
index 183207e90ab5b51fae5084eb341fefb4287eb45f..bee09ee87ffc31d7deb254b33348595fc61d61ed 100644 (file)
@@ -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),