Skip to content

Commit 3c423b2

Browse files
authored
Merge pull request #41 from lucianotonet/master
Start translating "guide/component-custom-events.md"
2 parents 8976555 + a2a45b7 commit 3c423b2

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

src/guide/component-custom-events.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
# Custom Events
1+
# Eventos Customizados
22

3-
> This page assumes you've already read the [Components Basics](component-basics.md). Read that first if you are new to components.
3+
> Esta página assume que você já leu o [Básico sobre Componentes](component-basics.md). Leia lá antes se você está iniciando com componentes.
44
5-
## Event Names
5+
## Nomes de Eventos
66

7-
Unlike components and props, event names don't provide any automatic case transformation. Instead, the name of an emitted event must exactly match the name used to listen to that event. For example, if emitting a camelCased event name:
7+
Diferente de componentes e propriedades, os nomes de eventos não convertem automaticamente maiúsculas e minúsculas. Em vez disso, o nome de um evento emitido deve corresponder exatamente ao nome usado para escutar este evento. Por exemplo, se emitir um evento com nome em camelCase:
88

99
```js
1010
this.$emit('myEvent')
1111
```
1212

13-
Listening to the kebab-cased version will have no effect:
13+
Escutar com kebab-case não funcionará:
1414

1515
```html
16-
<!-- Won't work -->
16+
<!-- Não funcionará -->
1717
<my-component @my-event="doSomething"></my-component>
1818
```
1919

20-
Since event names will never be used as variable or property names in JavaScript, there is no reason to use camelCase or PascalCase. Additionally, `v-on` event listeners inside DOM templates will be automatically transformed to lowercase (due to HTML's case-insensitivity), so `@myEvent` would become `@myevent` -- making `myEvent` impossible to listen to.
20+
Considerando que os nomes de eventos nunca serão usados como nomes de variáveis ou de propriedades no JavaScript, não há razão para usar camelCase ou PascalCase. Além disso, escutadores de eventos `v-on` dentro dos templates DOM serão automaticamente transformados em minúsculas (devido ao HTML ser insensível à maiúsculas e minúsculas), então `@myEvent` se tornará `@myevent` -- fazendo `myEvent` impossível de ser escutado.
2121

22-
For these reasons, we recommend you **always use kebab-case for event names**.
22+
Por estas razões, nós recomendamos que você **sempre use kebab-case para nomes de eventos**.
2323

24-
## Defining Custom Events
24+
## Definindo Eventos Customizados
2525

26-
<VideoLesson href="https://vueschool.io/lessons/defining-custom-events-emits?friend=vuejs" title="Learn how to define which events a component can emit with Vue School">Watch a free video about Defining Custom Events on Vue School</VideoLesson>
26+
<VideoLesson href="https://vueschool.io/lessons/defining-custom-events-emits?friend=vuejs" title="Aprenda à definir quais eventos um componente pode emitir com a Vue School (em inglês)">Assista um vídeo grátis sobre como definir Eventos Customizados na Vue School (em inglês)</VideoLesson>
2727

28-
Emitted events can be defined on the component via the `emits` option.
28+
Os eventos emitidos podem ser definidos no componente através da opção `emits`.
2929

3030
```js
3131
app.component('custom-form', {
3232
emits: ['in-focus', 'submit']
3333
})
3434
```
3535

36-
When a native event (e.g., `click`) is defined in the `emits` option, the component event will be used __instead__ of a native event listener.
36+
Quando um evento nativo (por exemplo, `click`) for definido na opção `emits`, o evento do componente será usado __ao invés__ de um escutador de evento nativo.
3737

38-
::: tip
39-
It is recommended to define all emitted events in order to better document how a component should work.
38+
::: tip DICA
39+
Recomenda-se definir todos os eventos emitidos para documentar melhor como o componente deve funcionar.
4040
:::
4141

42-
### Validate Emitted Events
42+
### Validar Eventos Emitidos
4343

44-
Similar to prop type validation, an emitted event can be validated if it is defined with the Object syntax instead of the Array syntax.
44+
Semelhante à validação de propriedades, um evento emitido pode ser validado se for definido com a sintaxe Object em vez da sintaxe Array.
4545

46-
To add validation, the event is assigned a function that receives the arguments passed to the `$emit` call and returns a boolean to indicate whether the event is valid or not.
46+
Para adicionar validação, o evento recebe uma função que recebe os argumentos passados ​​para a chamada `$emit` e retorna um booleano para indicar se o evento é válido ou não.
4747

4848
```js
4949
app.component('custom-form', {
5050
emits: {
51-
// No validation
51+
// Sem validação
5252
click: null,
5353

54-
// Validate submit event
54+
// Validar evento submit
5555
submit: ({ email, password }) => {
5656
if (email && password) {
5757
return true
5858
} else {
59-
console.warn('Invalid submit event payload!')
59+
console.warn('Argumentos inválidos para o evento submit!')
6060
return false
6161
}
6262
}
@@ -69,15 +69,15 @@ app.component('custom-form', {
6969
})
7070
```
7171

72-
## `v-model` arguments
72+
## Argumentos do `v-model`
7373

74-
By default, `v-model` on a component uses `modelValue` as the prop and `update:modelValue` as the event. We can modify these names passing an argument to `v-model`:
74+
Por padrão, em um componente o `v-model` usa `modelValue` como propriedade e `update:modelValue` como evento. Podemos modificar esses nomes passando um argumento para `v-model`:
7575

7676
```html
7777
<my-component v-model:title="bookTitle"></my-component>
7878
```
7979

80-
In this case, child component will expect a `title` prop and emits `update:title` event to sync:
80+
Nesse caso, o componente filho espera a propriedade `title` e emite o evento `update:title` para sincronizar:
8181

8282
```js
8383
const app = Vue.createApp({})
@@ -99,11 +99,11 @@ app.component('my-component', {
9999
<my-component v-model:title="bookTitle"></my-component>
100100
```
101101

102-
## Multiple `v-model` bindings
102+
## Múltiplos Vínculos `v-model`
103103

104-
By leveraging the ability to target a particular prop and event as we learned before with [`v-model` arguments](#v-model-arguments), we can now create multiple v-model bindings on a single component instance.
104+
Aproveitando a capacidade de direcionar uma determinada propriedade e evento como aprendemos antes em [argumentos do `v-model`](#argumentos-do-v-model), agora podemos criar múltiplos vínculos de `v-model` em uma única instância do componente.
105105

106-
Each v-model will sync to a different prop, without the need for extra options in the component:
106+
Cada `v-model` será sincronizado com uma propriedade diferente, sem a necessidade de opções extras no componente:
107107

108108
```html
109109
<user-name
@@ -134,22 +134,22 @@ app.component('user-name', {
134134
})
135135
```
136136

137-
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="html,result" data-user="Vue" data-slug-hash="GRoPPrM" data-preview="true" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Multiple v-models">
138-
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/GRoPPrM">
139-
Multiple v-models</a> by Vue (<a href="https://codepen.io/Vue">@Vue</a>)
140-
on <a href="https://codepen.io">CodePen</a>.</span>
137+
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="html,result" data-user="lucianotonet" data-slug-hash="bGpZrLy" data-preview="true" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Múltiplos v-models">
138+
<span>Veja o exemplo <a href="https://codepen.io/lucianotonet/pen/bGpZrLy">
139+
Múltiplos v-models</a> por L. Tonet (<a href="https://codepen.io/lucianotonet">@lucianotonet</a>)
140+
no <a href="https://codepen.io">CodePen</a>.</span>
141141
</p>
142142
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
143143

144-
## Handling `v-model` modifiers
144+
## Manipulando Modificadores do `v-model`
145145

146-
When we were learning about form input bindings, we saw that `v-model` has [built-in modifiers](/guide/forms.html#modifiers) - `.trim`, `.number` and `.lazy`. In some cases, however, you might also want to add your own custom modifiers.
146+
Quando estávamos aprendendo sobre interligações em elementos _input_, vimos que `v-model` tem [modificadores embutidos](/guide/forms.html#modifiers) - `.trim`, `.number` e `.lazy`. Em alguns casos, entretanto, você também pode querer adicionar seus próprios modificadores personalizados.
147147

148-
Let's create an example custom modifier, `capitalize`, that capitalizes the first letter of the string provided by the `v-model` binding.
148+
Vamos criar um modificador personalizado de exemplo, `capitalize`, que coloca em maiúscula a primeira letra da string fornecida pela vinculação `v-model`.
149149

150-
Modifiers added to a component `v-model` will be provided to the component via the `modelModifiers` prop. In the below example, we have created a component that contains a `modelModifiers` prop that defaults to an empty object.
150+
Modificadores adicionados ao `v-model` de um componente serão fornecidos ao componente por meio da propriedade `modelModifiers`. No exemplo abaixo, criamos um componente que contém uma propriedade `modelModifiers` cujo padrão é um objeto vazio.
151151

152-
Notice that when the component's `created` lifecycle hook triggers, the `modelModifiers` prop contains `capitalize` and its value is `true` - due to it being set on the `v-model` binding `v-model.capitalize="bar"`.
152+
Observe que quando o gatilho do ciclo de vida `created` do componente é acionado, a propriedade `modelModifiers` contém `capitalize` e seu valor é `true` - devido ao fato de ser definido na vinculação `v-model.capitalize="bar"`.
153153

154154
```html
155155
<my-component v-model.capitalize="bar"></my-component>
@@ -174,7 +174,7 @@ app.component('my-component', {
174174
})
175175
```
176176

177-
Now that we have our prop set up, we can check the `modelModifiers` object keys and write a handler to change the emitted value. In the code below we will capitalize the string whenever the `<input />` element fires an `input` event.
177+
Agora que temos nossa propriedade configurada, podemos verificar as chaves do objeto `modelModifiers` e escrever um manipulador para alterar o valor emitido. No código a seguir, colocaremos a string em maiúscula sempre que o elemento `<input />` disparar um evento `input`.
178178

179179
```html
180180
<div id="app">
@@ -217,7 +217,7 @@ app.component('my-component', {
217217
app.mount('#app')
218218
```
219219

220-
For `v-model` bindings with arguments, the generated prop name will be `arg + "Modifiers"`:
220+
Para os vínculos `v-model` com argumentos, o nome da propriedade gerada será `arg + "Modifiers"`:
221221

222222
```html
223223
<my-component v-model:foo.capitalize="bar"></my-component>

0 commit comments

Comments
 (0)