This commit is contained in:
Che Guevara 2025-05-05 20:41:47 +00:00 committed by GitHub
commit 3be608b535
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -526,6 +526,11 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
`but is not defined on instance.`,
)
}
} else if (__DEV__ && !__TEST__ && !isReservedPrefix(key[0])) {
warn(
`Property ${JSON.stringify(key)} was accessed during render ` +
`but is not defined on instance.`,
)
}
},

View File

@ -311,4 +311,27 @@ describe('compiler + runtime integration', () => {
app.mount(root)
expect(root.innerHTML).toBe('<div>60000000100000111</div>')
})
test('Warning when use undeclared variable in template', () => {
const app = createApp({
template: `
<div @click="handler">handler</div>
<div>dddd{{dddd}}</div>
<div>no warn: {{message}}</div>
`,
setup() {
return {
message: 'hello',
}
},
})
const root = document.createElement('div')
app.mount(root)
expect(
`[Vue warn]: Property "handler" was accessed during render but is not defined on instance.`,
).toHaveBeenWarned()
expect(
`[Vue warn]: Property "dddd" was accessed during render but is not defined on instance.`,
).toHaveBeenWarned()
})
})