Skip to content

Commit aefebea

Browse files
committed
translate into ja
1 parent 032c9d5 commit aefebea

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/guide/composition-api-setup.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
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

1616
### Props
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` 関数の 1 番目の引数は `props` 引数です。 標準コンポーネントで期待するように、`setup` 関数内の `props` はリアクティブで、新しい props が渡されたら更新されます。
1919

2020
```js
2121
// MyBook.vue
2222

2323
export default {
2424
props: {
25-
title: String
25+
title: String,
2626
},
2727
setup(props) {
2828
console.log(props.title)
29-
}
29+
},
3030
}
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
@@ -50,7 +50,7 @@ setup(props) {
5050

5151
### Context
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` 関数に渡される 2 番目の引数は `context` です。`context` は 3 つのコンポーネントプロパティを公開する一般的な JavaScript オブジェクトです。:
5454

5555
```js
5656
// MyBook.vue
@@ -65,11 +65,11 @@ export default {
6565

6666
// Emit Events (Method)
6767
console.log(context.emit)
68-
}
68+
},
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
@@ -142,10 +142,10 @@ export default {
142142
const book = reactive({ title: 'Vue 3 Guide' })
143143
// Please note that we need to explicitly expose ref value here
144144
return () => h('div', [readersNumber.value, book.title])
145-
}
145+
},
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)