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
It is also possible to add an "else block" with `v-else`:
11
+
これは、`v-else` で "else ブロック" を追加することも可能です:
12
12
13
13
```html
14
14
<h1v-if="awesome">Vue is awesome!</h1>
15
15
<h1v-else>Oh no 😢</h1>
16
16
```
17
17
18
-
### Conditional Groups with `v-if`on `<template>`
18
+
### `<template>` での `v-if`による条件グループ
19
19
20
-
Because `v-if`is a directive, it has to be attached to a single element. But what if we want to toggle more than one element? In this case we can use `v-if`on a `<template>`element, which serves as an invisible wrapper. The final rendered result will not include the `<template>` element.
Another option for conditionally displaying an element is the `v-show`directive. The usage is largely the same:
68
+
条件的に要素を表示するための別のオプションは `v-show`です。使用方法はほとんど同じです:
69
69
70
70
```html
71
71
<h1v-show="ok">Hello!</h1>
72
72
```
73
73
74
-
The difference is that an element with `v-show`will always be rendered and remain in the DOM; `v-show`only toggles the `display` CSS property of the element.
74
+
違いは `v-show`による要素は常に描画されて DOM に維持するということです。`v-show`はシンプルに要素の `display` CSS プロパティを切り替えます。
75
75
76
-
`v-show`doesn't support the `<template>`element, nor does it work with `v-else`.
`v-if`is "real" conditional rendering because it ensures that event listeners and child components inside the conditional block are properly destroyed and re-created during toggles.
`v-if`is also **lazy**: if the condition is false on initial render, it will not do anything - the conditional block won't be rendered until the condition becomes true for the first time.
Generally speaking, `v-if`has higher toggle costs while `v-show`has higher initial render costs. So prefer `v-show`if you need to toggle something very often, and prefer `v-if`if the condition is unlikely to change at runtime.
0 commit comments