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
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.
@@ -84,34 +84,34 @@ Because `v-if` is a directive, it has to be attached to a single element. But wh
84
84
</template>
85
85
```
86
86
87
-
`v-else`and`v-else-if`can also be used on `<template>`.
87
+
`v-else`と`v-else-if`は `<template>` でも使用可能です。
88
88
89
89
## `v-show`
90
90
91
-
Another option for conditionally displaying an element is the `v-show`directive. The usage is largely the same:
91
+
条件的に要素を表示するための別のオプションは `v-show`です。使用方法はほとんど同じです:
92
92
93
93
```vue-html
94
94
<h1 v-show="ok">Hello!</h1>
95
95
```
96
96
97
-
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.
97
+
違いは `v-show`による要素は常レンダリングされて DOM に残るということです。`v-show`はシンプルに要素の `display` CSS プロパティを切り替えます。
98
98
99
-
`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.
It's **not** recommended to use `v-if`and`v-for`on the same element due to implicit precedence. Refer to [style guide](/style-guide/rules-essential.html#avoid-v-if-with-v-for) for details.
When `v-if`and`v-for`are both used on the same element, `v-if`will be evaluated first. See the [list rendering guide](list#v-for-with-v-if)for details.
0 commit comments