]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): track access to $attrs
authorEvan You <yyx990803@gmail.com>
Fri, 12 Jun 2020 20:59:15 +0000 (16:59 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 12 Jun 2020 20:59:15 +0000 (16:59 -0400)
fix #1346

packages/runtime-core/src/componentProps.ts
packages/runtime-core/src/componentProxy.ts

index 0f6fecb14e61d6d311b82a63c77c583d3c0332b4..28f5ed00ea022fb6ed5cab54e5949edaf9845a46 100644 (file)
@@ -1,4 +1,9 @@
-import { toRaw, shallowReactive } from '@vue/reactivity'
+import {
+  toRaw,
+  shallowReactive,
+  trigger,
+  TriggerOpTypes
+} from '@vue/reactivity'
 import {
   EMPTY_OBJ,
   camelize,
@@ -215,6 +220,9 @@ export function updateProps(
     }
   }
 
+  // trigger updates for $attrs in case it's used in component slots
+  trigger(instance, TriggerOpTypes.SET, '$attrs')
+
   if (__DEV__ && rawProps) {
     validateProps(props, instance.type)
   }
index f986c3a82753f2b8d6a95832b455541ef20f1876..de7765d3f4db98ccfd4e7526d59da3c1331eab85 100644 (file)
@@ -13,7 +13,9 @@ import {
   UnwrapRef,
   toRaw,
   shallowReadonly,
-  ReactiveFlags
+  ReactiveFlags,
+  track,
+  TrackOpTypes
 } from '@vue/reactivity'
 import {
   ExtractComputedReturns,
@@ -260,8 +262,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
     let cssModule, globalProperties
     // public $xxx properties
     if (publicGetter) {
-      if (__DEV__ && key === '$attrs') {
-        markAttrsAccessed()
+      if (key === '$attrs') {
+        track(instance, TrackOpTypes.GET, key)
+        __DEV__ && markAttrsAccessed()
       }
       return publicGetter(instance)
     } else if (