fix(runtime-core): avoid script setup bindings overwriting reserved ctx properties (#4570)

This commit is contained in:
ygj6
2021-09-16 23:16:07 +08:00
committed by GitHub
parent a31303f835
commit 14fcced281
2 changed files with 64 additions and 14 deletions

View File

@@ -538,20 +538,22 @@ export function exposeSetupStateOnRenderContext(
) {
const { ctx, setupState } = instance
Object.keys(toRaw(setupState)).forEach(key => {
if (!setupState.__isScriptSetup && (key[0] === '$' || key[0] === '_')) {
warn(
`setup() return property ${JSON.stringify(
key
)} should not start with "$" or "_" ` +
`which are reserved prefixes for Vue internals.`
)
return
if (!setupState.__isScriptSetup) {
if (key[0] === '$' || key[0] === '_') {
warn(
`setup() return property ${JSON.stringify(
key
)} should not start with "$" or "_" ` +
`which are reserved prefixes for Vue internals.`
)
return
}
Object.defineProperty(ctx, key, {
enumerable: true,
configurable: true,
get: () => setupState[key],
set: NOOP
})
}
Object.defineProperty(ctx, key, {
enumerable: true,
configurable: true,
get: () => setupState[key],
set: NOOP
})
})
}