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
In Vue 2, functional components had two primary use cases:
21
+
Vue 2 では、関数型コンポーネントには 2 つの主要なユースケースがありました:
22
22
23
-
-as a performance optimization, because they initialized much faster than stateful components
24
-
-to return multiple root nodes
23
+
-ステートフルコンポーネントよりもはるかに高速に初期化されるので、パフォーマンスの最適化として
24
+
-複数のルートノードを返すため
25
25
26
-
However, in Vue 3, the performance of stateful components has improved to the point that the difference is negligible. In addition, stateful components now also include the ability to return multiple root nodes.
As a result, the only remaining use case for functional components is simple components, such as a component to create a dynamic heading. Otherwise, it is recommended to use stateful components as you normally would.
Using the `<dynamic-heading>`component, which is responsible for rendering out the appropriate heading (i.e., `h1`, `h2`, `h3`, etc.), this could have been written as a single-file component in 2.x as:
Or, for those who preferred the `<template>`in a single-file component:
45
+
または、単一ファイルコンポーネントの `<template>`を好む人向けに:
46
46
47
47
```js
48
-
// Vue 2 Functional Component Example with <template>
48
+
// Vue 2 での <template> を使用した関数型コンポーネントの例
49
49
<template functional>
50
50
<component
51
51
:is="`h${props.level}`"
@@ -61,17 +61,17 @@ export default {
61
61
</script>
62
62
```
63
63
64
-
## 3.x Syntax
64
+
## 3.x のシンタックス
65
65
66
-
### Components Created by Functions
66
+
### 関数で作られるコンポーネント
67
67
68
-
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.
They will receive two arguments: `props` and `context`. The `context`argument is an object that contains a component's `attrs`, `slots`, and `emit`properties.
In 3.x, 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.
0 commit comments