添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Skip to content

Conditional Rendering

v-if

The directive v-if is used to conditionally render a block. The block will only be rendered if the directive's expression returns a truthy value.

v-else

You can use the v-else directive to indicate an "else block" for v-if :

Vue is awesome!

A v-else element must immediately follow a v-if or a v-else-if element - otherwise it will not be recognized.

v-else-if

The v-else-if , as the name suggests, serves as an "else if block" for v-if . It can also be chained multiple times:

Similar to v-else , a v-else-if element must immediately follow a v-if or a v-else-if element.

v-if on <template>

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.