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
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.
5
+
A diretiva`v-if`é usada para renderizar condicionalmente um bloco. O bloco só será renderizado se a expressão da diretiva retornar um valor verdadeiro.
6
6
7
7
```html
8
-
<h1v-if="awesome">Vue is awesome!</h1>
8
+
<h1v-if="awesome">Vue é incrível!</h1>
9
9
```
10
10
11
-
It is also possible to add an "else block" with`v-else`:
11
+
Também é possível adicionar um "bloco senão" usando`v-else`:
12
12
13
13
```html
14
-
<h1v-if="awesome">Vue is awesome!</h1>
15
-
<h1v-else>Oh no 😢</h1>
14
+
<h1v-if="awesome">Vue é incrível!</h1>
15
+
<h1v-else>Oh não 😢</h1>
16
16
```
17
17
18
-
### Conditional Groups with`v-if`on`<template>`
18
+
### Grupos Condicionais com`v-if`em`<template>`
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.
20
+
Como`v-if`é uma diretiva, então deve ser anexado a um único elemento. E se quisermos alternar mais de um elemento? Nesse caso podemos usar `v-if`em um elemento `<template>`, que serve como um invólucro invisível. O resultado final renderizado não incluirá o elemento `<template>`.
21
21
22
22
```html
23
23
<templatev-if="ok">
24
-
<h1>Title</h1>
25
-
<p>Paragraph 1</p>
26
-
<p>Paragraph 2</p>
24
+
<h1>Título</h1>
25
+
<p>Parágrafo 1</p>
26
+
<p>Parágrafo 2</p>
27
27
</template>
28
28
```
29
29
30
30
### `v-else`
31
31
32
-
You can use the `v-else`directive to indicate an "else block" for`v-if`:
32
+
É possível utilizar a diretiva `v-else`para indicar um "bloco _else_" para`v-if`:
33
33
34
34
```html
35
35
<divv-if="Math.random() > 0.5">
36
-
Now you see me
36
+
Agora você me vê
37
37
</div>
38
38
<divv-else>
39
-
Now you don't
39
+
Agora você não me vê
40
40
</div>
41
41
```
42
42
43
-
A `v-else`element must immediately follow a `v-if`or a `v-else-if` element - otherwise it will not be recognized.
43
+
Um elemento `v-else`deve vir imediatamente após um elemento `v-if`ou `v-else-if`, caso contrário não será reconhecido.
44
44
45
45
### `v-else-if`
46
46
47
-
The`v-else-if`, as the name suggests, serves as an "else if block" for`v-if`. It can also be chained multiple times:
47
+
O`v-else-if`, como o nome sugere, serve como um "bloco _else if_" ao`v-if`. Ele pode, inclusive, ser encadeado várias vezes:
48
48
49
49
```html
50
50
<divv-if="type === 'A'">
@@ -57,38 +57,38 @@ The `v-else-if`, as the name suggests, serves as an "else if block" for `v-if`.
57
57
C
58
58
</div>
59
59
<divv-else>
60
-
Not A/B/C
60
+
Não A, B ou C
61
61
</div>
62
62
```
63
63
64
-
Similar to`v-else`, a`v-else-if`element must immediately follow a `v-if`or a `v-else-if` element.
64
+
Similar ao`v-else`, um`v-else-if`deve vir imediatamente após um elemento `v-if`ou um elemento `v-else-if`.
65
65
66
66
## `v-show`
67
67
68
-
Another option for conditionally displaying an element is the `v-show` directive. The usage is largely the same:
68
+
Outra opção para exibir condicionalmente um elemento é a diretiva `v-show`. A utilização é basicamente a mesma.
69
69
70
70
```html
71
-
<h1v-show="ok">Hello!</h1>
71
+
<h1v-show="ok">Olá!</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
+
A diferença é que um elemento com`v-show`sempre será renderizado e permanecerá no DOM; `v-show`simplesmente alterna a propriedade CSS `display`do elemento.
75
75
76
-
`v-show`doesn't support the `<template>` element, nor does it work with`v-else`.
76
+
`v-show`não suporta o elemento `<template>`, nem funciona com`v-else`.
77
77
78
78
## `v-if` vs `v-show`
79
79
80
-
`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.
80
+
`v-if`é a renderização condicional "real", pois garante que eventos e componentes filhos dentro do bloco condicional sejam devidamente destruídos e recriados durante a alternância.
81
81
82
-
`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.
82
+
`v-if`também é**preguiçoso**: se a condição for _false_ na renderização inicial, nada será feito - o bloco condicional não será renderizado até que a condição se torne _true_ pela primeira vez.
83
83
84
-
In comparison, `v-show`is much simpler - the element is always rendered regardless of initial condition, with CSS-based toggling.
84
+
Em comparação, `v-show`é mais simples - o elemento sempre será renderizado independentemente da condição inicial, com alternância baseada em CSS.
85
85
86
-
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.
86
+
De modo geral, `v-if`tem custo maior nas alternâncias de renderização, enquanto que `v-show`tem custo maior na renderização inicial. Então prefira`v-show`se precisar alternar a visibilidade de algo com muita frequência, e prefira`v-if`se não é muito provável que a condição se altere durante a execução.
87
87
88
88
## `v-if` with `v-for`
89
89
90
90
::: tip Note
91
-
Using`v-if`and`v-for`together is **not recommended**. See the [style guide](../style-guide/#avoid-v-if-with-v-for-essential)for further information.
91
+
Usar`v-if`e`v-for`juntos **não é recomendado**. Veja o [guia de estilos](../style-guide/#avoid-v-if-with-v-for-essential)para mais informações.
92
92
:::
93
93
94
-
When used together with `v-if`, `v-for`has a higher priority than`v-if`. See the [list rendering guide](list#v-for-with-v-if)for details.
94
+
Quando usado em conjunto com `v-if`, `v-for`possui maior prioridade do que`v-if`. Veja o [guia renderização de listas](list#v-for-with-v-if)para mais detalhes.
0 commit comments