You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/class-and-style.md
+27-27Lines changed: 27 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,32 @@
1
1
---
2
-
title: Class and Style Bindings
2
+
title: クラスとスタイルのバインディング
3
3
type: guide
4
4
order: 6
5
5
---
6
6
7
-
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 just 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.
We can pass an object to `v-bind:class`to dynamically toggle classes:
13
+
私達は、`v-bind:class`に動的にクラスを切り替えるオブジェクトを渡すことが出来ます:
14
14
15
15
```html
16
16
<divv-bind:class="{ active: isActive }"></div>
17
17
```
18
18
19
-
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`.
You can have multiple classes toggled by having more fields in the object. In addition, the `v-bind:class`directive can also co-exist with the plain `class`attribute. So given the following template:
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"`.
44
+
`isActive`と`hasError`が変化するとき、クラスリストはそれに応じて更新されます。例えば、`hasError`が`true` になった場合、クラスリストは `"static active text-danger"` になります。
45
45
46
-
The bound object doesn't have to be inline:
46
+
インラインでオブジェクトをバインドする必要はありません:
47
47
48
48
```html
49
49
<divv-bind:class="classObject"></div>
@@ -57,7 +57,7 @@ data: {
57
57
}
58
58
```
59
59
60
-
This will render the same result. We can also bind to a [computed property](computed.html) that returns an object. This is a common and powerful pattern:
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:
The object syntax for `v-bind:style` is pretty straightforward - it looks almost like CSS, except it's a JavaScript object. You can use either camelCase or kebab-case for the CSS property names:
When you use a CSS property that requires vendor prefixes in `v-bind:style`, for example `transform`, Vue will automatically detect and add appropriate prefixes to the applied styles.
0 commit comments