fix(runtime-core): track access to $attrs

fix #1346
This commit is contained in:
Evan You 2020-06-12 16:59:15 -04:00
parent 91fa52850a
commit 6abac87b3d
2 changed files with 15 additions and 4 deletions

View File

@ -1,4 +1,9 @@
import { toRaw, shallowReactive } from '@vue/reactivity' import {
toRaw,
shallowReactive,
trigger,
TriggerOpTypes
} from '@vue/reactivity'
import { import {
EMPTY_OBJ, EMPTY_OBJ,
camelize, 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) { if (__DEV__ && rawProps) {
validateProps(props, instance.type) validateProps(props, instance.type)
} }

View File

@ -13,7 +13,9 @@ import {
UnwrapRef, UnwrapRef,
toRaw, toRaw,
shallowReadonly, shallowReadonly,
ReactiveFlags ReactiveFlags,
track,
TrackOpTypes
} from '@vue/reactivity' } from '@vue/reactivity'
import { import {
ExtractComputedReturns, ExtractComputedReturns,
@ -260,8 +262,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
let cssModule, globalProperties let cssModule, globalProperties
// public $xxx properties // public $xxx properties
if (publicGetter) { if (publicGetter) {
if (__DEV__ && key === '$attrs') { if (key === '$attrs') {
markAttrsAccessed() track(instance, TrackOpTypes.GET, key)
__DEV__ && markAttrsAccessed()
} }
return publicGetter(instance) return publicGetter(instance)
} else if ( } else if (