Skip to content

Commit a981928

Browse files
committed
feat: require vue: prefix for lifecycle hooks
align with vue core 3.2.25+
1 parent be1f86c commit a981928

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ createApp({
116116

117117
### Lifecycle Events
118118

119-
You can listen to the `mounted` and `unmounted` lifecycle events for each element:
119+
You can listen to the special `vue:mounted` and `vue:unmounted` lifecycle events for each element:
120120

121121
```html
122122
<div
123123
v-if="show"
124-
@mounted="console.log('mounted on: ', $el)"
125-
@unmounted="console.log('unmounted: ', $el)"
124+
@vue:mounted="console.log('mounted on: ', $el)"
125+
@vue:unmounted="console.log('unmounted: ', $el)"
126126
></div>
127127
```
128128

Diff for: src/directives/on.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ export const on: Directive = ({ el, get, exp, arg, modifiers }) => {
4242
: get(`($event => { ${exp} })`)
4343

4444
// special lifecycle events
45-
if (arg === 'mounted') {
45+
if (import.meta.env.DEV && (arg === 'mounted' || arg === 'unmounted')) {
46+
console.error(
47+
`mounted and unmounted hooks now need to be prefixed with vue: ` +
48+
`- use @vue:${arg}="handler" instead.`
49+
)
50+
}
51+
if (arg === 'vue:mounted') {
4652
nextTick(handler)
4753
return
48-
} else if (arg === 'unmounted') {
54+
} else if (arg === 'vue:unmounted') {
4955
return () => handler()
5056
}
5157

0 commit comments

Comments
 (0)