Skip to content

Commit 325b474

Browse files
docs: add a migration entry for renaming hook: to vnode- (#857)
1 parent a8463c6 commit 325b474

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/.vuepress/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ const sidebar = {
203203
'/guide/migration/v-model',
204204
'/guide/migration/v-if-v-for',
205205
'/guide/migration/v-bind',
206+
'/guide/migration/vnode-lifecycle-events',
206207
'/guide/migration/watch'
207208
]
208209
}

src/guide/migration/introduction.md

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ The following consists a list of breaking changes from 2.x:
105105
- [When watching an array, the callback will only trigger when the array is replaced. If you need to trigger on mutation, the `deep` option must be specified.](/guide/migration/watch.html)
106106
- `<template>` tags with no special directives (`v-if/else-if/else`, `v-for`, or `v-slot`) are now treated as plain elements and will result in a native `<template>` element instead of rendering its inner content.
107107
- In Vue 2.x, application root container's `outerHTML` is replaced with root component template (or eventually compiled to a template, if root component has no template/render option). Vue 3.x now uses application container's `innerHTML` instead - this means the container itself is no longer considered part of the template.
108+
- [Lifecycle `hook:` events prefix changed to `vnode-`](/guide/migration/vnode-lifecycle-events.html)
108109

109110
### Removed APIs
110111

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)