Skip to content

Commit aae8226

Browse files
committed
Translation of api/instance-methods
1 parent 73c8736 commit aae8226

File tree

1 file changed

+76
-76
lines changed

1 file changed

+76
-76
lines changed

src/api/instance-methods.md

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Instance Methods
1+
# Métodos de Instância
22

33
## $watch
44

5-
- **Arguments:**
5+
- **Argumentos:**
66

77
- `{string | Function} source`
88
- `{Function | Object} callback`
@@ -11,13 +11,13 @@
1111
- `{boolean} immediate`
1212
- `{string} flush`
1313

14-
- **Returns:** `{Function} unwatch`
14+
- **Retorno:** `{Function} unwatch`
1515

16-
- **Usage:**
16+
- **Uso:**
1717

18-
Watch a reactive property or a computed function on the component instance for changes. The callback gets called with the new value and the old value for the given property. We can only pass top-level `data`, `props`, or `computed` property name as a string. For more complex expressions or nested properties, use a function instead.
18+
Observa uma propriedade reativa ou uma função computada na instância do componente esperando alterações. O _callback_ é chamado com o novo valor e o valor antigo para a propriedade fornecida. Só podemos passar o nome da propriedade `data`, `props` ou `computed` de nível superior como uma string. Para expressões mais complexas ou propriedades aninhadas, use uma função.
1919

20-
- **Example:**
20+
- **Exemplo:**
2121

2222
```js
2323
const app = createApp({
@@ -32,67 +32,67 @@
3232
}
3333
},
3434
created() {
35-
// top-level property name
35+
// nome da propriedade de nível superior
3636
this.$watch('a', (newVal, oldVal) => {
37-
// do something
37+
// faça algo
3838
})
3939

40-
// function for watching a single nested property
40+
// função para observar uma única propriedade aninhada
4141
this.$watch(
4242
() => this.c.d,
4343
(newVal, oldVal) => {
44-
// do something
44+
// faça algo
4545
}
4646
)
4747

48-
// function for watching a complex expression
48+
// função para observar uma expressão complexa
4949
this.$watch(
50-
// every time the expression `this.a + this.b` yields a different result,
51-
// the handler will be called. It's as if we were watching a computed
52-
// property without defining the computed property itself
50+
// toda vez que a expressão `this.a + this.b` produz um resultado diferente,
51+
// o manipulador será chamado. É como se estivéssemos observando
52+
// um dado computado sem precisarmos definí-lo
5353
() => this.a + this.b,
5454
(newVal, oldVal) => {
55-
// do something
55+
// faça algo
5656
}
5757
)
5858
}
5959
})
6060
```
6161

62-
When watched value is an object or array, any changes to its properties or elements won't trigger the watcher because they reference the same object/array:
62+
Quando o valor observado é um objeto ou array, quaisquer alterações em suas propriedades ou elementos não acionarão o inspetor porque fazem referência ao mesmo objeto/array:
6363

6464
```js
6565
const app = createApp({
6666
data() {
6767
return {
6868
article: {
69-
text: 'Vue is awesome!'
69+
text: 'Vue é incrível!'
7070
},
71-
comments: ['Indeed!', 'I agree']
71+
comments: ['De fato!', 'Concordo']
7272
}
7373
},
7474
created() {
7575
this.$watch('article', () => {
76-
console.log('Article changed!')
76+
console.log('Artigo alterado!')
7777
})
7878

7979
this.$watch('comments', () => {
80-
console.log('Comments changed!')
80+
console.log('Comentários alterados!')
8181
})
8282
},
8383
methods: {
84-
// These methods won't trigger a watcher because we changed only a property of object/array,
85-
// not the object/array itself
84+
// Esses métodos não acionarão um observador pois alteramos apenas uma propriedade do object/array,
85+
// não o objeto/array em si
8686
changeArticleText() {
87-
this.article.text = 'Vue 3 is awesome'
87+
this.article.text = 'Vue 3 é incrível'
8888
},
8989
addComment() {
90-
this.comments.push('New comment')
90+
this.comments.push('Novo comentário')
9191
},
9292

93-
// These methods will trigger a watcher because we replaced object/array completely
93+
// Esses métodos acionarão um observador pois substituímos o objeto/array completamente
9494
changeWholeArticle() {
95-
this.article = { text: 'Vue 3 is awesome' }
95+
this.article = { text: 'Vue 3 é incrível' }
9696
},
9797
clearComments() {
9898
this.comments = []
@@ -101,7 +101,7 @@
101101
})
102102
```
103103

104-
`$watch` returns an unwatch function that stops firing the callback:
104+
`$watch` retorna uma função `unwatch` que para de disparar o _callback_:
105105

106106
```js
107107
const app = createApp({
@@ -115,39 +115,39 @@
115115
const vm = app.mount('#app')
116116

117117
const unwatch = vm.$watch('a', cb)
118-
// later, teardown the watcher
118+
// depois, desmonta o observador
119119
unwatch()
120120
```
121121

122-
- **Option: deep**
122+
- **Opção: `deep`**
123123

124-
To also detect nested value changes inside Objects, you need to pass in `deep: true` in the options argument. This option also can be used to watch array mutations.
124+
Para também detectar mudanças de valores aninhados dentro de Objects, você precisa passar `deep: true` no argumento de opções. Esta opção também pode ser usada para observar mutações de array.
125125

126-
> Note: when mutating (rather than replacing) an Object or an Array and watch with deep option, the old value will be the same as new value because they reference the same Object/Array. Vue doesn't keep a copy of the pre-mutate value.
126+
> Nota: ao mudar (ao invés de substituir) um Object ou um Array e observar com a opção `deep`, o valor antigo será o mesmo que o novo valor porque eles fazem referência ao mesmo Object/Array. O Vue não mantém uma cópia do valor pré-modificação.
127127
128128
```js
129129
vm.$watch('someObject', callback, {
130130
deep: true
131131
})
132132
vm.someObject.nestedValue = 123
133-
// callback is fired
133+
// callback é acionado
134134
```
135135

136-
- **Option: immediate**
136+
- **Opção: `immediate`**
137137

138-
Passing in `immediate: true` in the option will trigger the callback immediately with the current value of the expression:
138+
Passar `immediate: true` na opção acionará o _callback_ imediatamente com o valor atual da expressão:
139139

140140
```js
141141
vm.$watch('a', callback, {
142142
immediate: true
143143
})
144-
// `callback` is fired immediately with current value of `a`
144+
// `callback` é acionado imediatamente com o valor atual de `a`
145145
```
146146

147-
Note that with `immediate` option you won't be able to unwatch the given property on the first callback call.
147+
Observe que com a opção `immediate` você não poderá dar _unwatch_ na propriedade fornecida na primeira chamada de _callback_.
148148

149149
```js
150-
// This will cause an error
150+
// Isso causará um erro
151151
const unwatch = vm.$watch(
152152
'value',
153153
function() {
@@ -158,7 +158,7 @@
158158
)
159159
```
160160

161-
If you still want to call an unwatch function inside the callback, you should check its availability first:
161+
Se você ainda quiser chamar uma função _unwatch_ dentro do _callback_, verifique primeiro sua disponibilidade:
162162

163163
```js
164164
let unwatch = null
@@ -175,38 +175,38 @@
175175
)
176176
```
177177

178-
- **Option: flush**
178+
- **Opção: flush**
179179

180-
The `flush` option allows for greater control over the timing of the callback. It can be set to `'pre'`, `'post'` or `'sync'`.
180+
A opção `flush` permite maior controle sobre o momento de acionamento do _callback_. Pode ser definido como `'pre'`, `'post'` ou `'sync'`.
181181

182-
The default value is `'pre'`, which specifies that the callback should be invoked before rendering. This allows the callback to update other values before the template runs.
182+
O valor padrão é `'pre'`, que especifica que o _callback_ deve ser invocado antes da renderização. Isso permite que o _callback_ atualize outros valores antes que o _template_ seja executado.
183183

184-
The value `'post'` can be used to defer the callback until after rendering. This should be used if the callback needs access to the updated DOM or child components via `$refs`.
184+
O valor `'post'` pode ser usado para adiar o _callback_ até depois da renderização. Isso deve ser usado se o _callback_ precisar acessar o DOM atualizado ou componentes filho por meio de `$refs`.
185185

186-
If `flush` is set to `'sync'`, the callback will be called synchronously, as soon as the value changes.
186+
Se `flush` for definido como `'sync'`, o _callback_ será chamado de forma síncrona, assim que o valor mudar.
187187

188-
For both `'pre'` and `'post'`, the callback is buffered using a queue. The callback will only be added to the queue once, even if the watched value changes multiple times. The interim values will be skipped and won't be passed to the callback.
188+
Para ambos `'pre'` e `'post'`, o _callback_ é armazenado em _buffer_ usando uma fila. O _callback_ será adicionado à fila apenas uma vez, mesmo que o valor observado seja alterado várias vezes. Os valores provisórios serão ignorados e não serão passados ​​para o _callback_.
189189

190-
Buffering the callback not only improves performance but also helps to ensure data consistency. The watchers won't be triggered until the code performing the data updates has finished.
190+
O armazenamento em _buffer_ do _callback_ não apenas melhora o desempenho, mas também ajuda a garantir a consistência dos dados. Os observadores não serão acionados até que o código que executa as atualizações de dados seja concluído.
191191

192-
`'sync'` watchers should be used sparingly, as they don't have these benefits.
192+
Observadores `'sync'` devem ser usados ​​com moderação, pois eles não têm esses benefícios.
193193

194-
For more information about `flush` see [Effect Flush Timing](../guide/reactivity-computed-watchers.html#effect-flush-timing).
194+
Para obter mais informações sobre `flush`, consulte [Momento de Limpeza do Efeito](../guide/reactivity-computed-watchers.html#momento-de-limpeza-do-efeito).
195195

196-
- **See also:** [Watchers](../guide/computed.html#watchers)
196+
- **Ver também:** [Observadores](../guide/computed.html#observadores)
197197

198-
## $emit
198+
## `$emit`
199199

200-
- **Arguments:**
200+
- **Argumentos:**
201201

202202
- `{string} eventName`
203-
- `...args (optional)`
203+
- `...args (opcional)`
204204

205-
Trigger an event on the current instance. Any additional arguments will be passed into the listener's callback function.
205+
Acionar um evento na instância atual. Quaisquer argumentos adicionais serão passados ​​para a função _callback_ do escutador.
206206

207-
- **Examples:**
207+
- **Exemplos:**
208208

209-
Using `$emit` with only an event name:
209+
Usando `$emit` com apenas um nome de evento:
210210

211211
```html
212212
<div id="emit-example-simple">
@@ -218,7 +218,7 @@
218218
const app = createApp({
219219
methods: {
220220
sayHi() {
221-
console.log('Hi!')
221+
console.log('Oi!')
222222
}
223223
}
224224
})
@@ -227,15 +227,15 @@
227227
emits: ['welcome'],
228228
template: `
229229
<button v-on:click="$emit('welcome')">
230-
Click me to be welcomed
230+
Clique-me para as boas vindas
231231
</button>
232232
`
233233
})
234234

235235
app.mount('#emit-example-simple')
236236
```
237237

238-
Using `$emit` with additional arguments:
238+
Usando `$emit` com argumentos adicionais:
239239

240240
```html
241241
<div id="emit-example-argument">
@@ -256,14 +256,14 @@
256256
emits: ['advise'],
257257
data() {
258258
return {
259-
adviceText: 'Some advice'
259+
adviceText: 'Alguns conselhos'
260260
}
261261
},
262262
template: `
263263
<div>
264264
<input type="text" v-model="adviceText">
265265
<button v-on:click="$emit('advise', adviceText)">
266-
Click me for sending advice
266+
Clique em mim para enviar conselhos
267267
</button>
268268
</div>
269269
`
@@ -272,45 +272,45 @@
272272
app.mount('#emit-example-argument')
273273
```
274274

275-
- **See also:**
276-
- [`emits` option](./options-data.html#emits)
277-
- [Emitting a Value With an Event](../guide/component-basics.html#emitting-a-value-with-an-event)
275+
- **Ver também:**
276+
- [Opção `emits`](./options-data.html#emits)
277+
- [Emitindo um Valor Com um Evento](../guide/component-basics.html#emitindo-um-valor-com-um-evento)
278278

279-
## $forceUpdate
279+
## `$forceUpdate`
280280

281-
- **Usage:**
281+
- **Uso:**
282282

283-
Force the component instance to re-render. Note it does not affect all child components, only the instance itself and child components with inserted slot content.
283+
Força a instância do componente a renderizar novamente. Observe que isso não afeta todos os componentes filho, apenas a própria instância e os componentes filho com conteúdo de _slot_ inserido.
284284

285-
## $nextTick
285+
## `$nextTick`
286286

287-
- **Arguments:**
287+
- **Argumentos:**
288288

289-
- `{Function} callback (optional)`
289+
- `{Function} callback (opcional)`
290290

291-
- **Usage:**
291+
- **Uso:**
292292

293-
Defer the callback to be executed after the next DOM update cycle. Use it immediately after you've changed some data to wait for the DOM update. This is the same as the global `nextTick`, except that the callback's `this` context is automatically bound to the instance calling this method.
293+
Adie o _callback_ para ser executado após o próximo ciclo de atualização do DOM. Use-o imediatamente após alterar alguns dados para aguardar a atualização do DOM. Isso é o mesmo que o `nextTick` global, exceto que o contexto `this` do _callback_ é automaticamente vinculado à instância que chama esse método.
294294

295-
- **Example:**
295+
- **Exemplo:**
296296

297297
```js
298298
createApp({
299299
// ...
300300
methods: {
301301
// ...
302302
example() {
303-
// modify data
303+
// modifica os dados
304304
this.message = 'changed'
305-
// DOM is not updated yet
305+
// DOM ainda não foi atualizado
306306
this.$nextTick(function() {
307-
// DOM is now updated
308-
// `this` is bound to the current instance
307+
// DOM agora está atualizado
308+
// `this` está vinculado à instância atual
309309
this.doSomethingElse()
310310
})
311311
}
312312
}
313313
})
314314
```
315315

316-
- **See also:** [nextTick](global-api.html#nexttick)
316+
- **Ver também:** [nextTick](global-api.html#nexttick)

0 commit comments

Comments
 (0)