You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/migration/functional-components.md
+41-5
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,15 @@
5
5
In terms of what has changed, at a high level:
6
6
7
7
- Performance gains from v2 for functional components are now negligible in v3, so we recommend just using stateful components
8
-
-`functional` attribute on single-file component `<template>` is deprecated
9
8
- Functional components can only be created using a plain function that receives `props` and `context` (i.e., `slots`, `attrs`, `emit`)
9
+
-**DEPRECATED:**`functional` attribute on single-file component (SFC) `<template>` is deprecated
10
+
-**DEPRECATED:**`{ functional: true }` option in components created by functions is deprecated
10
11
11
-
For a more in-depth explanation, read on!
12
+
For more information, read on!
12
13
13
14
## Introduction
14
15
15
-
In Vue 2, functional components had primary use cases:
16
+
In Vue 2, functional components had two primary use cases:
16
17
17
18
- as a performance optimization, because they initialized much faster than stateful components
18
19
- to return multiple root nodes
@@ -53,12 +54,19 @@ export default {
53
54
props: ['level']
54
55
}
55
56
</script>
56
-
57
57
```
58
58
59
59
## Current Syntax
60
60
61
-
Now in Vue 3, the only way to create a functional component is with a plain function that receives `props` and a `context` object that contains `attrs`, `slots`, and `emit` options:
61
+
### Components Created by Functions
62
+
63
+
Now in Vue 3, all functional components are created with a plain function. In other words, there is no need to define the `{ functional: true }` component option.
64
+
65
+
They will receive two arguments: `props` and `context`. The `context` argument is an object that contains a component's `attrs`, `slots`, and `emit` properties.
66
+
67
+
In addition, rather than implicitly provide provide `h` in a `render` function, `h` is now imported globally.
68
+
69
+
Using the previously mentioned example of a `<dynamic-heading>` component, here is how it looks now.
In v3, the performance difference between stateful and functional components has been drastically reduced and will be insignificant in most use cases. As a result, the migration path for developers using `functional` on SFCs is to remove the attribute. No additional work required.
86
+
87
+
Using our `<dynamic-heading>` example from before, here is how it would look now.
88
+
89
+
```js{1}
90
+
<template>
91
+
<component
92
+
v-bind:is="`h${props.level}`"
93
+
v-bind="$attrs"
94
+
/>
95
+
</template>
96
+
97
+
<script>
98
+
export default {
99
+
props: ['level']
100
+
}
101
+
</script>
102
+
```
103
+
104
+
The main differences are that:
105
+
106
+
1.`functional` attribute removed on `<template>`
107
+
1.`listeners` are now passed as part of `$attrs` and can be removed
108
+
109
+
## Next Steps
110
+
75
111
For more information on the usage of the new functional components and the changes to render functions in general, see:
0 commit comments