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 {
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)
}

View 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 (