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
A component option that is executed **before** the component is created, once the `props`are resolved. It serves as the entry point for composition APIs.
7
+
コンポーネントが作成される **前に**、一度 `props`が解決されると、このコンポーネントオプションが実行されます。Composition API のエントリポイントとして提供します。
8
8
9
-
-**Arguments:**
9
+
-**引数:**
10
10
11
11
-`{Data} props`
12
12
-`{SetupContext} context`
13
13
14
-
Similar to `this.$props`when using Options API, the `props`object will only contain explicitly declared props. Also, all declared prop keys will be present on the `props`object, regardless of whether it was passed by the parent component or not. Absent optional props will have a value of `undefined`.
14
+
オプション API を使うときの `this.$props`と同様に、`props`オブジェクトには明示的に宣言されたプロパティのみが含まれます。また、すべての宣言されたプロパティのキーは、親コンポーネントから渡されたかどうかに関わらず `props`オブジェクトに存在します。宣言されていない省略可能なプロパティは `undefined` という値になります。
15
15
16
-
If you need to check the absence of an optional prop, you can give it a Symbol as its default value:
16
+
省略可能なプロパティがないことを確認する必要があるなら、デフォルト値として Symbol を指定できます:
17
17
18
18
```js
19
19
constisAbsent=Symbol()
@@ -24,13 +24,13 @@ A component option that is executed **before** the component is created, once th
24
24
},
25
25
setup(props) {
26
26
if (props.foo=== isAbsent) {
27
-
// foo was not provided.
27
+
// foo は提供されませんでした
28
28
}
29
29
}
30
30
}
31
31
```
32
32
33
-
-**Typing**:
33
+
-**型**:
34
34
35
35
```ts
36
36
interfaceData {
@@ -48,12 +48,12 @@ A component option that is executed **before** the component is created, once th
48
48
```
49
49
50
50
::: tip
51
-
Togettypeinference for the arguments passed to `setup()`, the use of [defineComponent](global-api.html#definecomponent) is needed.
Ifyoureturnarenderfunction then you can't return any other properties. If you need to expose properties so that they can be accessed externally, e.g. via a `ref` in the parent, you can use `expose`:
Lifecycle hooks can be registered with directly-imported `onX`functions:
128
+
ライフサイクルフックは、直接インポートされた `onX`関数に登録できます:
129
129
130
130
```js
131
131
import { onMounted, onUpdated, onUnmounted } from 'vue'
@@ -145,14 +145,14 @@ const MyComponent = {
145
145
}
146
146
```
147
147
148
-
These lifecycle hook registration functions can only be used synchronously during [`setup()`](#setup), since they rely on internal global state to locate the current active instance (the component instance whose `setup()`is being called right now). Calling them without a current active instance will result in an error.
The component instance context is also set during the synchronous execution of lifecycle hooks. As a result, watchers and computed properties created synchronously inside of lifecycle hooks are also automatically tore down when the component unmounts.
0 commit comments