Skip to content

Commit 837f622

Browse files
committed
Merge branch 'lang-ja' of https://github.com/vuejs-jp/ja.vuejs.org into lang-ja
2 parents 77e4437 + 7a11c3f commit 837f622

File tree

3 files changed

+112
-112
lines changed

3 files changed

+112
-112
lines changed

src/guide/class-and-style.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# Class and Style Bindings
1+
# クラスとスタイルのバインディング
22

3-
A common need for data binding is manipulating an element's class list and its inline styles. Since they are both attributes, we can use `v-bind` to handle them: we only need to calculate a final string with our expressions. However, meddling with string concatenation is annoying and error-prone. For this reason, Vue provides special enhancements when `v-bind` is used with `class` and `style`. In addition to strings, the expressions can also evaluate to objects or arrays.
3+
データバインディングに一般に求められることの 1 つは、要素のクラスリストとインラインスタイルを操作することです。それらはどちらも属性であるため、`v-bind` を使って扱うことができます。最終的な文字列を式で計算するだけです。しかしながら、文字列の連結に手を出すのは煩わしく、エラーのもとです。そのため、Vue `v-bind` `class` `style` と一緒に使われるとき、特別な拡張機能を提供します。文字列だけではなく、式はオブジェクトまたは配列を返すことができます。
44

5-
## Binding HTML Classes
5+
## HTML クラスのバインディング
66

7-
### Object Syntax
7+
### オブジェクト構文
88

9-
We can pass an object to `:class` (short for `v-bind:class`) to dynamically toggle classes:
9+
`:class` (`v-bind:class` の略) にオブジェクトを渡すことでクラスを動的に切り替えることができます:
1010

1111
```html
1212
<div :class="{ active: isActive }"></div>
1313
```
1414

15-
The above syntax means the presence of the `active` class will be determined by the [truthiness](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) of the data property `isActive`.
15+
上記の構文は、`active` クラスの有無がデータプロパティ `isActive`[真偽性](https://developer.mozilla.org/ja-JP/docs/Glossary/Truthy)によって決まることを意味しています。
1616

17-
You can have multiple classes toggled by having more fields in the object. In addition, the `:class` directive can also co-exist with the plain `class` attribute. So given the following template:
17+
オブジェクトにさらにフィールドを持たせることで複数のクラスを切り替えることができます。加えて、`:class` ディレクティブはプレーンな `class` 属性と共存できます。つまり、次のようなテンプレートと:
1818

1919
```html
2020
<div
@@ -23,7 +23,7 @@ You can have multiple classes toggled by having more fields in the object. In ad
2323
></div>
2424
```
2525

26-
And the following data:
26+
次のようなデータがあったとすると:
2727

2828
```js
2929
data() {
@@ -34,15 +34,15 @@ data() {
3434
}
3535
```
3636

37-
It will render:
37+
このように描画されます:
3838

3939
```html
4040
<div class="static active"></div>
4141
```
4242

43-
When `isActive` or `hasError` changes, the class list will be updated accordingly. For example, if `hasError` becomes `true`, the class list will become `"static active text-danger"`.
43+
`isActive` もしくは `hasError` が変化するとき、クラスリストはそれに応じて更新されます。例えば、`hasError` `true` になった場合、クラスリストは `"static active text-danger"` になります。
4444

45-
The bound object doesn't have to be inline:
45+
束縛されるオブジェクトはインラインでなくてもかまいません:
4646

4747
```html
4848
<div :class="classObject"></div>
@@ -59,7 +59,7 @@ data() {
5959
}
6060
```
6161

62-
This will render the same result. We can also bind to a [computed property](computed.md) that returns an object. This is a common and powerful pattern:
62+
これは同じ結果を描画します。オブジェクトを返す[算出プロパティ](computed.md)に束縛することもできます。これは一般的で強力なパターンです:
6363

6464
```html
6565
<div :class="classObject"></div>
@@ -82,9 +82,9 @@ computed: {
8282
}
8383
```
8484

85-
### Array Syntax
85+
### 配列構文
8686

87-
We can pass an array to `:class` to apply a list of classes:
87+
`:class` に配列を渡してクラスのリストを適用することができます:
8888

8989
```html
9090
<div :class="[activeClass, errorClass]"></div>
@@ -99,33 +99,33 @@ data() {
9999
}
100100
```
101101

102-
Which will render:
102+
これは次のように描画されます:
103103

104104
```html
105105
<div class="active text-danger"></div>
106106
```
107107

108-
If you would like to also toggle a class in the list conditionally, you can do it with a ternary expression:
108+
リスト内のクラスを条件に応じて切り替えたい場合は、三項演算子式を使って実現することができます:
109109

110110
```html
111111
<div :class="[isActive ? activeClass : '', errorClass]"></div>
112112
```
113113

114-
This will always apply `errorClass`, but will only apply `activeClass` when `isActive` is truthy.
114+
この場合 `errorClass` は常に適用されますが、`activeClass` クラスは `isActive` が真と評価されるときだけ適用されます。
115115

116-
However, this can be a bit verbose if you have multiple conditional classes. That's why it's also possible to use the object syntax inside array syntax:
116+
しかしながら、これでは複数の条件つきクラスがあると少し冗長になってしまいます。そのため、配列構文の内部ではオブジェクト構文を使うこともできます:
117117

118118
```html
119119
<div :class="[{ active: isActive }, errorClass]"></div>
120120
```
121121

122-
### With Components
122+
### コンポーネントにおいて
123123

124-
> This section assumes knowledge of [Vue Components](component-basics.md). Feel free to skip it and come back later.
124+
> このセクションでは、[Vue のコンポーネント](component-basics.md)の知識を前提としています。いったんスキップして後で戻ってきても構いません。
125125
126-
When you use the `class` attribute on a custom component with a single root element, those classes will be added to this element. Existing classes on this element will not be overwritten.
126+
単一のルート要素を持つカスタムコンポーネントで `class` 属性を使用すると、それらのクラスがこの要素に追加されます。この要素の既存のクラスは上書きされません。
127127

128-
For example, if you declare this component:
128+
例えば、このコンポーネントを宣言して:
129129

130130
```js
131131
const app = Vue.createApp({})
@@ -135,33 +135,33 @@ app.component('my-component', {
135135
})
136136
```
137137

138-
Then add some classes when using it:
138+
使用するときにいくつかのクラスを追加したとします:
139139

140140
```html
141141
<div id="app">
142142
<my-component class="baz boo"></my-component>
143143
</div>
144144
```
145145

146-
The rendered HTML will be:
146+
以下の HTML が描画されます:
147147

148148
```html
149149
<p class="foo bar baz boo">Hi</p>
150150
```
151151

152-
The same is true for class bindings:
152+
クラスバインディングに対しても同様です:
153153

154154
```html
155155
<my-component :class="{ active: isActive }"></my-component>
156156
```
157157

158-
When `isActive` is truthy, the rendered HTML will be:
158+
`isActive` が真と評価されるときは、以下の HTML が描画されます:
159159

160160
```html
161161
<p class="foo bar active">Hi</p>
162162
```
163163

164-
If your component has multiple root elements, you would need to define which component will receive this class. You can do this using `$attrs` component property:
164+
コンポーネントに複数のルート要素がある場合、どのコンポーネントがこのクラスを受け取るかを定義する必要があります。これは `$attrs` コンポーネントプロパティを使って行うことができます:
165165

166166
```html
167167
<div id="app">
@@ -180,13 +180,13 @@ app.component('my-component', {
180180
})
181181
```
182182

183-
You can learn more about component attribute inheritance in [Non-Prop Attributes](component-attrs.html) section.
183+
コンポーネント属性の継承については、[プロパティでない属性](component-attrs.html)のセクションを参照してください。
184184

185-
## Binding Inline Styles
185+
## インラインスタイルのバインディング
186186

187-
### Object Syntax
187+
### オブジェクト構文
188188

189-
The object syntax for `:style` is pretty straightforward - it looks almost like CSS, except it's a JavaScript object. You can use either camelCase or kebab-case (use quotes with kebab-case) for the CSS property names:
189+
`:style` 向けのオブジェクト構文は非常に簡単です。JavaScript オブジェクトということを除けば、ほとんど CSS のように見えます。CSS のプロパティ名には、キャメルケース (camelCase) またはケバブケース (kebab-case: クォートとともに使うことになります) のどちらでも使用することができます:
190190

191191
```html
192192
<div :style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
@@ -201,7 +201,7 @@ data() {
201201
}
202202
```
203203

204-
It is often a good idea to bind to a style object directly so that the template is cleaner:
204+
テンプレートをクリーンにするために、直接 style オブジェクトに束縛するのは、よいアイディアです:
205205

206206
```html
207207
<div :style="styleObject"></div>
@@ -218,26 +218,26 @@ data() {
218218
}
219219
```
220220

221-
Again, the object syntax is often used in conjunction with computed properties that return objects.
221+
ここでもまた、オブジェクト構文はしばしばオブジェクトを返す算出プロパティと併せて使用されます。
222222

223-
### Array Syntax
223+
### 配列構文
224224

225-
The array syntax for `:style` allows you to apply multiple style objects to the same element:
225+
`:style` 向けの配列構文は、同じ要素に複数のスタイルオブジェクトを適用することができます:
226226

227227
```html
228228
<div :style="[baseStyles, overridingStyles]"></div>
229229
```
230230

231-
### Auto-prefixing
231+
### 自動プリフィックス
232232

233-
When you use a CSS property that requires [vendor prefixes](https://developer.mozilla.org/en-US/docs/Glossary/Vendor_Prefix) in `:style`, for example `transform`, Vue will automatically detect and add appropriate prefixes to the applied styles.
233+
`:style`[ベンダー接頭辞](https://developer.mozilla.org/ja/docs/Glossary/Vendor_Prefix)を要求される CSS プロパティを使用するとき、例えば、`transform` においては、Vue.js は自動的に適切な接頭辞を検出し、適用されるスタイルに追加します。
234234

235-
### Multiple Values
235+
### 複数の値
236236

237-
You can provide an array of multiple (prefixed) values to a style property, for example:
237+
style プロパティに複数の (接頭辞付き) 値の配列を設定できます。例えば次のようになります:
238238

239239
```html
240240
<div :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"></div>
241241
```
242242

243-
This will only render the last value in the array which the browser supports. In this example, it will render `display: flex` for browsers that support the unprefixed version of flexbox.
243+
これは、配列内でブラウザがサポートしている最後の値だけを描画します。この例では、flexbox の接頭されていないバージョンをサポートしているブラウザでは `display: flex` を描画します。

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)