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
+45-44Lines changed: 45 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,20 @@
1
-
# Class and Style Bindings
1
+
# Interligações de Classe e Estilo
2
2
3
-
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 only 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.
3
+
Uma necessidade comum de interligação de dados é manipular as classes dos elementos e seus estilos _inline_. Uma vez que ambos são atributos, podemos usar `v-bind`para lidar com eles: apenas precisamos calcular uma String final com nossas expressões. No entanto, mexer com concatenação de String é irritante e propenso a erros. Por esta razão, Vue fornece aprimoramentos especiais quando`v-bind`é usado com`class`e`style`. Além de Strings, as expressões também podem avaliar Objetos ou Arrays.
4
4
5
-
## Binding HTML Classes
5
+
## Interligando Classes HTML
6
6
7
-
### Object Syntax
7
+
### Sintaxe do Objeto
8
8
9
-
We can pass an object to `:class` (short for`v-bind:class`) to dynamically toggle classes:
9
+
Podemos passar um objeto para `:class` (abreviação de`v-bind:class`) para alternar classes dinamicamente:
10
10
11
11
```html
12
12
<div:class="{ active: isActive }"></div>
13
13
```
14
14
15
-
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`.
15
+
A sintaxe acima significa que a presença da classe `active`será determinada pela [veracidade](https://developer.mozilla.org/pt-BR/docs/Glossary/Truthy)do valor do dado`isActive`.
16
16
17
-
You can have multiple classes toggled by having more fields in the object. In addition, the `:class`directive can also co-exist with the plain `class` attribute. So given the following template:
17
+
Você pode ter múltiplas classes alternadas tendo mais campos no objeto. Além disso, a diretiva `:class`também pode coexistir com um atributo de classe "normal". Então, dado o seguinte modelo:
18
18
19
19
```html
20
20
<div
@@ -23,7 +23,7 @@ You can have multiple classes toggled by having more fields in the object. In ad
23
23
></div>
24
24
```
25
25
26
-
And the following data:
26
+
E os seguintes dados:
27
27
28
28
```js
29
29
data() {
@@ -34,15 +34,15 @@ data() {
34
34
}
35
35
```
36
36
37
-
It will render:
37
+
Irá renderizar:
38
38
39
39
```html
40
40
<divclass="static active"></div>
41
41
```
42
42
43
-
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"`.
43
+
Quando`isActive`ou`hasError`mudar, a lista de classes será atualizada correspondentemente. Por exemplo, se`hasError`é`true`, a lista de classes será`"static active text-danger"`.
44
44
45
-
The bound object doesn't have to be inline:
45
+
O objeto vinculado não precisa estar diretamente no _template_:
46
46
47
47
```html
48
48
<div:class="classObject"></div>
@@ -59,7 +59,7 @@ data() {
59
59
}
60
60
```
61
61
62
-
This will render the same result. We can also bind to a [computed property](computed.md)that returns an object. This is a common and powerful pattern:
62
+
Isso irá renderizar o mesmo resultado. Podemos também interligar a um [dado computado](computed.md)que retorne um objeto. Este é um padrão comum e poderoso:
63
63
64
64
```html
65
65
<div:class="classObject"></div>
@@ -82,9 +82,9 @@ computed: {
82
82
}
83
83
```
84
84
85
-
### Array Syntax
85
+
### Sintaxe de Array
86
86
87
-
We can pass an array to `:class`to apply a list of classes:
87
+
Podemos passar um Array para `:class`para aplicar uma lista de classes:
88
88
89
89
```html
90
90
<div:class="[activeClass, errorClass]"></div>
@@ -99,69 +99,69 @@ data() {
99
99
}
100
100
```
101
101
102
-
Which will render:
102
+
Que renderizará:
103
103
104
104
```html
105
105
<divclass="active text-danger"></div>
106
106
```
107
107
108
-
If you would like to also toggle a class in the list conditionally, you can do it with a ternary expression:
108
+
Se você preferir também alternar entre uma classe na lista condicionalmente, use uma expressão ternária:
This will always apply `errorClass`, but will only apply `activeClass`when`isActive`is truthy.
114
+
Isso sempre aplicará `errorClass`, mas somente aplicará `activeClass`quando`isActive`for verdadeiro.
115
115
116
-
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:
116
+
No entanto, isso pode ser um tanto prolixo se você tiver várias classes condicionais. Por isso também é possível usar a sintaxe de objeto dentro da sintaxe de Array:
> This section assumes knowledge of [Vue Components](component-basics.md). Feel free to skip it and come back later.
124
+
> Esta seção assume conhecimento sobre [Componentes Vue](component-basics.md). Pode pular esta parte e voltar depois.
125
125
126
-
When you use the `class`attribute on a custom component with a single root element, those classes will be added to this element. Existing classes on this element will not be overwritten.
126
+
Quando você usa o atributo `class`em um componente personalizado com um único elemento raiz, essas classes serão adicionadas a este elemento. As classes existentes neste elemento não serão substituídas.
127
127
128
-
For example, if you declare this component:
128
+
Por exemplo, se você declarar este componente:
129
129
130
130
```js
131
131
constapp=Vue.createApp({})
132
132
133
133
app.component('my-component', {
134
-
template:`<p class="foo bar">Hi!</p>`
134
+
template:`<p class="foo bar">Oi!</p>`
135
135
})
136
136
```
137
137
138
-
Then add some classes when using it:
138
+
E então adicionar mais classes quando for utilizá-lo:
When`isActive`is truthy, the rendered HTML will be:
158
+
Quando`isActive`for verdadeiro, o HTML renderizado será:
159
159
160
160
```html
161
-
<pclass="foo bar active">Hi</p>
161
+
<pclass="foo bar active">Oi!</p>
162
162
```
163
163
164
-
If your component has multiple root elements, you would need to define which component will receive this class. You can do this using `$attrs` component property:
164
+
Se o seu componente tiver vários elementos raiz, você precisará definir qual componente receberá essa classe utilizando a propriedade do componente `$attrs`:
You can learn more about component attribute inheritance in [Non-Prop Attributes](component-attrs.html) section.
183
+
Você pode aprender mais sobre herança de atributo de componente na seção [Atributos Não-Prop](component-attrs.html).
184
184
185
-
## Binding Inline Styles
185
+
## Interligando Estilos Inline
186
186
187
187
### Object Syntax
188
+
### Sintaxe de Objeto
188
189
189
-
The object syntax for `:style`is pretty straightforward - it looks almost like CSS, except it's a JavaScript object. You can use either camelCase or kebab-case (use quotes with kebab-case) for the CSS property names:
190
+
A sintaxe de objeto para `:style`é bem direta - parece quase como CSS, mas é um objeto JavaScript. Você pode usar tanto _camelCase_ quanto _kebab-case_ (use aspas com _kebab-case_) para os nomes das propriedades CSS.
When you use a CSS property that requires [vendor prefixes](https://developer.mozilla.org/en-US/docs/Glossary/Vendor_Prefix)in`:style`, for example`transform`, Vue will automatically detect and add appropriate prefixes to the applied styles.
234
+
Quando você usa uma propriedade CSS que requer [prefixos de fabricantes](https://developer.mozilla.org/pt-BR/docs/Glossary/Vendor_Prefix)em`:style`, por exemplo`transform`, Vue irá automaticamente detectar e adicionar os prefixos apropriados para os estilos aplicados.
234
235
235
-
### Multiple Values
236
+
### Valores Múltiplos
236
237
237
-
You can provide an array of multiple (prefixed) values to a style property, for example:
238
+
Você pode prover um Array com múltiplos valores (prefixados) para estilizar um atributo, por exemplo:
This will only render the last value in the array which the browser supports. In this example, it will render `display: flex`for browsers that support the unprefixed version of flexbox.
244
+
Isto irá renderizar apenas o último valor do Array que o navegador suportar. Neste exemplo, irá renderizar `display: flex`nos navegadores que suportam a versão sem prefixo do módulo Flexbox.
0 commit comments