Skip to content

Commit 90b9a85

Browse files
authored
docs: Advanced Guides > Compotion API > Setup (#62)
* translate into ja * 微修正 * 見出しのProps、Contextも翻訳した
1 parent 8b16dda commit 90b9a85

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/guide/composition-api-setup.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# Setup
1+
# セットアップ
22

3-
> This section uses [single-file component](single-file-component.html) syntax for code examples
3+
> このセクションではコード例に[単一ファイルコンポーネント](single-file-component.html)のシンタックスを使います。
44
5-
> This guide assumes that you have already read the [Composition API Introduction](composition-api-introduction.html) and [Reactivity Fundamentals](reactivity-fundamentals.html). Read that first if you are new to Composition API.
5+
> このガイドは[コンポジション API の導入](composition-api-introduction.html)[リアクティブの基礎](reactivity-fundamentals.html)を既に読んでいることを想定しています。 コンポジション API に初めて触れる方は、まずそちらを読んでみてください。
66
7-
## Arguments
7+
## 引数
88

9-
When using the `setup` function, it will take two arguments:
9+
`setup` 関数を使う時、2 つの引数を取ります:
1010

1111
1. `props`
1212
2. `context`
1313

14-
Let's dive deeper into how each argument can be used.
14+
それぞれの引数がどのように使われるのか、深く掘り下げてみましょう。
1515

16-
### Props
16+
### プロパティ
1717

18-
The first argument in the `setup` function is the `props` argument. Just as you would expect in a standard component, `props` inside of a `setup` function are reactive and will be updated when new props are passed in.
18+
`setup` 関数の 第一引数は `props` 引数です。 標準コンポーネントで期待するように、`setup` 関数内の `props` はリアクティブで、新しい props が渡されたら更新されます。
1919

2020
```js
2121
// MyBook.vue
@@ -31,10 +31,10 @@ export default {
3131
```
3232

3333
:::warning
34-
However, because `props` are reactive, you **cannot use ES6 destructuring** because it will remove props reactivity.
34+
しかし、`props` はリアクティブなので、props のリアクティブを削除してしまうため、**ES6 の分割代入を使うことができません。**
3535
:::
3636

37-
If you need to destructure your props, you can do this safely by utilizing the [toRefs](reactivity-fundamentals.html#destructuring-reactive-state) inside of the `setup` function.
37+
もし、props を分割代入する必要がある場合は、`setup` 関数内で [toRefs](reactivity-fundamentals.html#destructuring-reactive-state) を使うことによって安全に分割代入を行うことができます。
3838

3939
```js
4040
// MyBook.vue
@@ -48,9 +48,9 @@ setup(props) {
4848
}
4949
```
5050

51-
### Context
51+
### コンテキスト
5252

53-
The second argument passed to the `setup` function is the `context`. The `context` is a normal JavaScript object that exposes three component properties:
53+
`setup` 関数に渡される第二引数は `context` です。`context` は 3 つのコンポーネントプロパティを公開する一般的な JavaScript オブジェクトです。:
5454

5555
```js
5656
// MyBook.vue
@@ -69,7 +69,7 @@ export default {
6969
}
7070
```
7171

72-
The `context` object is a normal JavaScript object, i.e., it is not reactive, this means you can safely use ES6 destructuring on `context`.
72+
`context` オブジェクトは一般的な JavaScript オブジェクトです。 すなわち、リアクティブではありません。これは `context`ES6 分割代入を安全に使用できることを意味します。
7373

7474
```js
7575
// MyBook.vue
@@ -80,26 +80,26 @@ export default {
8080
}
8181
```
8282

83-
`attrs` and `slots` are stateful objects that are always updated when the component itself is updated. This means you should avoid destructuring them and always reference properties as `attrs.x` or `slots.x`. Also note that unlike `props`, `attrs` and `slots` are **not** reactive. If you intend to apply side effects based on `attrs` or `slots` changes, you should do so inside an `onUpdated` lifecycle hook.
83+
`attrs` `slots` はステートフルなオブジェクトです。コンポーネント自身が更新されたとき、常に更新されます。 つまり、分割代入の使用を避け、`attrs.x` `slots.x` のようにプロパティを常に参照する必要があります。 また、`props`とは異なり、 `attrs` `slots` はリアクティブ**ではない**ということに注意してください。 もし、`attrs` `slots` の変更による副作用を適用したいのなら、`onUpdated` ライフサイクルフックの中で行うべきです。
8484

85-
## Accessing Component Properties
85+
## コンポーネントプロパティへのアクセス
8686

87-
When `setup` is executed, the component instance has not been created yet. As a result, you will only be able to access the following properties:
87+
`setup` が実行されるとき、 コンポーネントインスタンスはまだ作成されていません。そのため、以下のプロパティにのみアクセスすることができます。:
8888

8989
- `props`
9090
- `attrs`
9191
- `slots`
9292
- `emit`
9393

94-
In other words, you **will not have access** to the following component options:
94+
言い換えると、以下のコンポーネントオプションには**アクセスできません**:
9595

9696
- `data`
9797
- `computed`
9898
- `methods`
9999

100-
## Usage with Templates
100+
## テンプレートでの使用
101101

102-
If `setup` returns an object, the properties on the object can be accessed in the component's template:
102+
`setup` がオブジェクトを返す場合、コンポーネントのテンプレート内でオブジェクトのプロパティにアクセスすることができます。:
103103

104104
```vue-html
105105
<!-- MyBook.vue -->
@@ -125,11 +125,11 @@ If `setup` returns an object, the properties on the object can be accessed in th
125125
</script>
126126
```
127127

128-
Note that [refs](../api/refs-api.html#ref) returned from `setup` are [automatically unwrapped](../api/refs-api.html#access-in-templates) when accessed in the template so you shouldn't use `.value` in templates.
128+
`setup` から返された [refs](../api/refs-api.html#ref) は、テンプレート内でアクセスされたときに[自動的にアンラップ](../api/refs-api.html#access-in-templates)されるので、テンプレート内で `.value` を使用すべきではないことに注意してください。
129129

130-
## Usage with Render Functions
130+
## 描画関数での使用
131131

132-
`setup` can also return a render function which can directly make use of the reactive state declared in the same scope:
132+
`setup` は同じスコープで宣言されたリアクティブなステートを直接利用することができる描画関数を返すこともできます。:
133133

134134
```js
135135
// MyBook.vue
@@ -140,12 +140,12 @@ export default {
140140
setup() {
141141
const readersNumber = ref(0)
142142
const book = reactive({ title: 'Vue 3 Guide' })
143-
// Please note that we need to explicitly expose ref value here
143+
// ここでは明示的に ref の値を公開する必要があることに注意してください。
144144
return () => h('div', [readersNumber.value, book.title])
145145
}
146146
}
147147
```
148148

149-
## Usage of `this`
149+
## `this` の使用
150150

151-
**Inside `setup()`, `this` won't be a reference to the current active instance** Since `setup()` is called before other component options are resolved, `this` inside `setup()` will behave quite differently from `this` in other options. This might cause confusions when using `setup()` along other Options API.
151+
**`setup()` 内では、`this` は現在のアクティブなインスタンスへの参照にはなりません。** `setup()` は他のコンポーネントオプションが解決される前に呼び出されるので、`setup()` 内の`this` は他のオプション内の `this`とは全く異なる振る舞いをします。 これは、`setup()` を他のオプション API と一緒に使った場合に混乱を引き起こす可能性があります。

0 commit comments

Comments
 (0)