Skip to content

Commit deed18f

Browse files
bobstrangekazupon
andauthored
docs: Advanced Guides > Compotion API > Provide / Inject の翻訳 (#96)
* docs: translate composition-api-provide-inject into ja * Update src/guide/composition-api-provide-inject.md Co-authored-by: kazuya kawaguchi <[email protected]> * doc: Fix review feedback Co-authored-by: kazuya kawaguchi <[email protected]>
1 parent f2aac68 commit deed18f

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/guide/composition-api-provide-inject.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Provide / Inject
22

3-
> This guide assumes that you have already read [Provide / Inject](component-provide-inject.html), [Composition API Introduction](composition-api-introduction.html), and [Reactivity Fundamentals](reactivity-fundamentals.html).
3+
> このページは、すでに [Provide / Inject](component-provide-inject.html)[コンポジション API 導入](composition-api-introduction.html)[リアクティブの基礎](reactivity-fundamentals.html)を読み終えていることを想定しています。
44
5-
We can use [provide / inject](component-provide-inject.html) with the Composition API as well. Both can only be called during [`setup()`](composition-api-setup.html) with a current active instance.
5+
[provide / inject](component-provide-inject.html) は コンポジション API でも使うことができます。どちらも現在アクティブなインスタンスの [`setup()`](composition-api-setup.html) 中にのみ呼び出すことが可能です。
66

7-
## Scenario Background
7+
## シナリオの背景
88

9-
Let's assume that we want to rewrite the following code, which contains a `MyMap` component that provides a `MyMarker` component with the user's location, using the Composition API.
9+
これから、コンポジション API を使用して、以下のコードを書き直そうとしているとしましょう。以下のコードでは、`MyMap` コンポーネントが `MyMaker` コンポーネントにユーザの位置情報を提供しています。
1010

1111
```vue
1212
<!-- src/components/MyMap.vue -->
@@ -41,16 +41,16 @@ export default {
4141
</script>
4242
```
4343

44-
## Using Provide
44+
## Provide の使い方
4545

46-
When using `provide` in `setup()`, we start by explicitly importing the method from `vue`. This allows us to define each property with its own invocation of `provide`.
46+
`provide` `setup()` 内で使う場合、始めに `vue` から明示的に `provide` をインポートします。これにより、 各プロパティについて `provide` の呼び出しで定義することができるようになります。
4747

48-
The `provide` function allows you to define the property through two parameters:
48+
`provide` 関数は2つの引数によってプロパティを定義できます:
4949

50-
1. The property's name (`<String>` type)
51-
2. The property's value
50+
1. プロパティの名前 (`<String>` )
51+
2. プロパティの値
5252

53-
Using our `MyMap` component, our provided values can be refactored as the following:
53+
`MyMap` コンポーネントは、以下のようにリファクタリングすることができます:
5454

5555
```vue{7,14-20}
5656
<!-- src/components/MyMap.vue -->
@@ -77,16 +77,16 @@ export default {
7777
</script>
7878
```
7979

80-
## Using Inject
80+
## Inject の使い方
8181

82-
When using `inject` in `setup()`, we also need to explicitly import it from `vue`. Once we do so, this allows us to invoke it to define how we want to expose it to our component.
82+
`inject` `setup()` 内で使う場合も、`vue` から明示的に `inject` をインポートする必要があります。そうしておけば、これを呼び出すことで、注入された値をコンポーネントに公開する方法を定義することができるようになります。
8383

84-
The `inject` function takes two parameters:
84+
`inject` 関数は2つの引数をとります:
8585

86-
1. The name of the property to inject
87-
2. A default value (**Optional**)
86+
1. 注入されるプロパティ名
87+
2. デフォルト値 (**任意**)
8888

89-
Using our `MyMarker` component, we can refactor it with the following code:
89+
`MyMaker` コンポーネントは、以下のようにリファクタリングすることができます:
9090

9191
```vue{3,6-14}
9292
<!-- src/components/MyMarker.vue -->
@@ -107,13 +107,13 @@ export default {
107107
</script>
108108
```
109109

110-
## Reactivity
110+
## リアクティブ
111111

112-
### Adding Reactivity
112+
### リアクティブの追加
113113

114-
To add reactivity between provided and injected values, we can use a [ref](reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs) or [reactive](reactivity-fundamentals.html#declaring-reactive-state) when providing a value.
114+
提供された値と注入された値をリアクティブにするには、値を提供する際に [ref](reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs) または [reactive](reactivity-fundamentals.html#declaring-reactive-state) を使います。
115115

116-
Using our `MyMap` component, our code can be updated as follows:
116+
`MyMap` コンポーネントは、以下のように変更できます:
117117

118118
```vue{7,15-22}
119119
<!-- src/components/MyMap.vue -->
@@ -143,13 +143,13 @@ export default {
143143
</script>
144144
```
145145

146-
Now, if anything changes in either property, the `MyMarker` component will automatically be updated as well!
146+
これで、どちらかのプロパティに何か変更があった場合、`MyMaker` コンポーネントも自動的に更新されるようになります。
147147

148-
### Mutating Reactive Properties
148+
### リアクティブプロパティの変更
149149

150-
When using reactive provide / inject values, **it is recommended to keep any mutations to reactive properties inside of the _provider_ whenever possible**.
150+
リアクティブな provide / inject の値を使う場合、**リアクティブなプロパティに対しての変更は可能な限り _提供する側_ の内部に留めることが推奨されます**
151151

152-
For example, in the event we needed to change the user's location, we would ideally do this inside of our `MyMap` component.
152+
例えば、以下の location を変更する必要があるイベントでは、location の変更は `MyMap` コンポーネント内で行われるのが理想的です。
153153

154154
```vue{28-32}
155155
<!-- src/components/MyMap.vue -->
@@ -188,7 +188,7 @@ export default {
188188
</script>
189189
```
190190

191-
However, there are times where we need to update the data inside of the component where the data is injected. In this scenario, we recommend providing a method that is responsible for mutating the reactive property.
191+
しかし、データが注入されたコンポーネント側でデータを更新する必要がある場合もあります。そのような場合、リアクティブなプロパティを更新する責務を持つメソッドを提供することを推奨します。
192192

193193
```vue{21-23,27}
194194
<!-- src/components/MyMap.vue -->
@@ -244,7 +244,7 @@ export default {
244244
</script>
245245
```
246246

247-
Finally, we recommend using `readonly` on provided property if you want to ensure that the data passed through `provide` cannot be mutated by the injected component.
247+
最後に、`provide` で渡したデータが、注入されたコンポーネント内で変更されないようにしたい場合は、提供するプロパティに `readonly` をつけることを推奨します。
248248

249249
```vue{7,25-26}
250250
<!-- src/components/MyMap.vue -->

0 commit comments

Comments
 (0)