Skip to content

Commit 6b67026

Browse files
committed
docs: translate composition api
1 parent 4698fb6 commit 6b67026

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

src/api/composition-api.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
オプション API を使うときの `this.$props` と同様に、`props` オブジェクトには明示的に宣言されたプロパティのみが含まれます。また、すべての宣言されたプロパティのキーは、親コンポーネントから渡されたかどうかに関わらず `props` オブジェクトに存在します。宣言されていない省略可能なプロパティは `undefined` という値になります。
1515

16-
If you need to check the absence of an optional prop, you can give it a Symbol as its default value:
16+
省略可能なプロパティが、ないことを確認する必要があるなら、デフォルト値として Symbol を指定できます:
1717

1818
```js
1919
const isAbsent = Symbol()
@@ -24,7 +24,7 @@
2424
},
2525
setup(props) {
2626
if (props.foo === isAbsent) {
27-
// foo was not provided.
27+
// foo は提供されませんでした
2828
}
2929
}
3030
}
@@ -48,12 +48,12 @@
4848
```
4949

5050
::: tip
51-
To get type inference for the arguments passed to `setup()`, the use of [defineComponent](global-api.html#definecomponent) is needed.
51+
`setup()` に渡された引数の型推論を得るためには、[defineComponent](global-api.html#definecomponent) を使用する必要があります。
5252
:::
5353

5454
- ****
5555

56-
With the template:
56+
テンプレートを使用する場合:
5757

5858
```vue-html
5959
<!-- MyBook.vue -->
@@ -69,7 +69,7 @@
6969
const readersNumber = ref(0)
7070
const book = reactive({ title: 'Vue 3 Guide' })
7171
72-
// expose to template
72+
// テンプレートに公開する
7373
return {
7474
readersNumber,
7575
book
@@ -79,7 +79,7 @@
7979
</script>
8080
```
8181

82-
With render function:
82+
Render 関数を使用する場合:
8383

8484
```js
8585
// MyBook.vue
@@ -90,13 +90,13 @@
9090
setup() {
9191
const readersNumber = ref(0)
9292
const book = reactive({ title: 'Vue 3 Guide' })
93-
// Please note that we need to explicitly use ref value here
93+
// ここでは明示的に ref 値を使う必要があることに注意してください
9494
return () => h('div', [readersNumber.value, book.title])
9595
}
9696
}
9797
```
9898

99-
If you return a render function 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`:
99+
Render 関数を返す場合は、他のプロパティを返すことはできません。プロパティを公開して、外部からアクセスする必要がある場合、例えば親の `ref` を介してなど、`expose` を使用できます:
100100

101101
```js
102102
// MyBook.vue
@@ -106,12 +106,12 @@
106106
export default {
107107
setup(props, { expose }) {
108108
const reset = () => {
109-
// Some reset logic
109+
// いくつかのリセットロジック
110110
}
111111
112-
// Expose can only be called once.
113-
// If you need to expose multiple properties, they must all
114-
// be included in the object passed to expose.
112+
// expose は一度しか呼べません。
113+
// 複数のプロパティを公開する必要があるなら、
114+
// expose に渡されたオブジェクトにすべてのプロパティを含める必要があります。
115115
expose({
116116
reset
117117
})
@@ -125,7 +125,7 @@
125125

126126
## ライフサイクルフック
127127

128-
Lifecycle hooks can be registered with directly-imported `onX` functions:
128+
ライフサイクルフックは、直接インポートされた `onX` 関数に登録できます:
129129

130130
```js
131131
import { onMounted, onUpdated, onUnmounted } from 'vue'
@@ -145,9 +145,9 @@ const MyComponent = {
145145
}
146146
```
147147

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.
148+
これらのライフサイクルフック登録関数は、[`setup()`](#setup) の間にのみ、同期的に使用できます。これらの関数は、現在アクティブなインスタンス(今まさに `setup()` が呼び出されているコンポーネントインスタンス)を見つけるために内部のグローバル状態に依存しています。現在アクティブなインスタンスがない状態でそれらを呼び出すと、エラーになります。
149149

150-
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.
150+
コンポーネントのインスタンスコンテキストは、ライフサイクルフックの同期的な実行中にも設定されます。その結果、ライフサイクルフック内で同期的に作成されたウォッチャと算出プロパティも、コンポーネントがアンマウントされるとき自動的に破棄されます。
151151

152152
- **オプション API のライフサイクルオプションと Composition API のマッピング**
153153

@@ -170,7 +170,7 @@ The component instance context is also set during the synchronous execution of l
170170

171171
## Provide / Inject
172172

173-
`provide` and `inject` enables dependency injection. Both can only be called during [`setup()`](#setup) with a current active instance.
173+
`provide` `inject` は依存性の注入を可能にします。 どちらも現在アクティブなインスタンスの [`setup()`](#setup) でのみ呼び出すことができます。
174174

175175
- ****:
176176

@@ -179,31 +179,31 @@ The component instance context is also set during the synchronous execution of l
179179
180180
function provide<T>(key: InjectionKey<T> | string, value: T): void
181181
182-
// without default value
182+
// デフォルト値なし
183183
function inject<T>(key: InjectionKey<T> | string): T | undefined
184-
// with default value
184+
// デフォルト値あり
185185
function inject<T>(key: InjectionKey<T> | string, defaultValue: T): T
186-
// with factory
186+
// ファクトリあり
187187
function inject<T>(
188188
key: InjectionKey<T> | string,
189189
defaultValue: () => T,
190190
treatDefaultAsFactory: true
191191
): T
192192
```
193193

194-
Vue provides an `InjectionKey` interface which is a generic type that extends `Symbol`. It can be used to sync the type of the injected value between the provider and the consumer:
194+
Vue `Symbol` を拡張したジェネリック型の `InjectionKey` インターフェイスを提供しています。これはプロバイダとコンシューマの間で注入された値の型を同期するために使用できます:
195195

196196
```ts
197197
import { InjectionKey, provide, inject } from 'vue'
198198
199199
const key: InjectionKey<string> = Symbol()
200200
201-
provide(key, 'foo') // providing non-string value will result in error
201+
provide(key, 'foo') // string 以外の値を指定するとエラーになります
202202
203-
const foo = inject(key) // type of foo: string | undefined
203+
const foo = inject(key) // foo の型: string | undefined
204204
```
205205

206-
If using string keys or non-typed symbols, the type of the injected value will need to be explicitly declared:
206+
文字列キーや型指定のない Symbol を使用する場合、注入される値の型を明示的に宣言する必要があります:
207207

208208
```ts
209209
const foo = inject<string>('foo') // string | undefined
@@ -215,10 +215,10 @@ The component instance context is also set during the synchronous execution of l
215215

216216
## `getCurrentInstance`
217217

218-
`getCurrentInstance` enables access to an internal component instance.
218+
`getCurrentInstance` は内部コンポーネントのインスタンスへのアクセスを可能にします。
219219

220220
:::warning
221-
`getCurrentInstance` is only exposed for advanced use cases, typically in libraries. Usage of `getCurrentInstance` is strongly discouraged in application code. Do **NOT** use it as an escape hatch to get the equivalent of `this` in Composition API.
221+
`getCurrentInstance` は高度なユースケースのみ、通常はライブラリに公開されます。アプリケーションコードで `getCurrentInstance` の使用は強くおすすめしません。Composition API`this` に相当するものを取得するための避難用ハッチとして **使用しない** でください。
222222
:::
223223

224224
```ts
@@ -228,31 +228,31 @@ const MyComponent = {
228228
setup() {
229229
const internalInstance = getCurrentInstance()
230230
231-
internalInstance.appContext.config.globalProperties // access to globalProperties
231+
internalInstance.appContext.config.globalProperties // globalProperties へのアクセス
232232
}
233233
}
234234
```
235235

236-
`getCurrentInstance` **only** works during [setup](#setup) or [Lifecycle Hooks](#lifecycle-hooks)
236+
`getCurrentInstance` [setup](#setup) または [ライフサイクルフック](#ライフサイクルフック) 中で **のみ** 動作します。
237237

238-
> When using outside of [setup](#setup) or [Lifecycle Hooks](#lifecycle-hooks), please call `getCurrentInstance()` on `setup` and use the instance instead.
238+
> [setup](#setup) や [ライフサイクルフック](#ライフサイクルフック) の外で使用する場合は、`setup` `getCurrentInstance()` を呼び出し、代わりにインスタンスを使用してください。
239239

240240
```ts
241241
const MyComponent = {
242242
setup() {
243-
const internalInstance = getCurrentInstance() // works
243+
const internalInstance = getCurrentInstance() // 動作します
244244
245-
const id = useComponentId() // works
245+
const id = useComponentId() // 動作します
246246
247247
const handleClick = () => {
248-
getCurrentInstance() // doesn't work
249-
useComponentId() // doesn't work
248+
getCurrentInstance() // 動作しません
249+
useComponentId() // 動作しません
250250
251-
internalInstance // works
251+
internalInstance // 動作します
252252
}
253253
254254
onMounted(() => {
255-
getCurrentInstance() // works
255+
getCurrentInstance() // 動作します
256256
})
257257
258258
return () =>
@@ -266,7 +266,7 @@ const MyComponent = {
266266
}
267267
}
268268
269-
// also works if called on a composable
269+
// composable で呼び出された場合も動作します
270270
function useComponentId() {
271271
return getCurrentInstance().uid
272272
}

0 commit comments

Comments
 (0)