Skip to content

Commit c43ab35

Browse files
committed
feat: add migration guide > vnode lifecycle events
1 parent 5c63b27 commit c43ab35

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
badges:
3+
- breaking
4+
---
5+
6+
# VNode Lifecycle Events <MigrationBadges :badges="$frontmatter.badges" />
7+
8+
## Overview
9+
10+
In Vue 2, it was possible to use events to listen for key stages in a component's lifecycle. These events had names that started with the prefix `hook:`, followed by the name of the corresponding lifecycle hook.
11+
12+
In Vue 3, this prefix has been changed to `vnode-`. In addition, these events are now available for HTML elements as well as components.
13+
14+
## 2.x Syntax
15+
16+
In Vue 2, the event name is the same as the equivalent lifecycle hook, prefixed with `hook:`:
17+
18+
```html
19+
<template>
20+
<child-component @hook:updated="onUpdated">
21+
</template>
22+
```
23+
24+
## 3.x Syntax
25+
26+
In Vue 3, the event name is prefixed with `vnode-`:
27+
28+
```html
29+
<template>
30+
<child-component @vnode-updated="onUpdated">
31+
</template>
32+
```
33+
34+
Or just `vnode` if you're using camel case:
35+
36+
```html
37+
<template>
38+
<child-component @vnodeUpdated="onUpdated">
39+
</template>
40+
```
41+
42+
## Migration Strategy
43+
44+
In most cases it should just require changing the prefix. The lifecycle hooks `beforeDestroy` and `destroyed` have been renamed to `beforeUnmount` and `unmounted` respectively, so the corresponding event names will also need to be updated.
45+
46+
## See also
47+
48+
- [Migration guide - Events API](/guide/migration/events-api.html)

0 commit comments

Comments
 (0)