Skip to content

Commit d4f1897

Browse files
committed
Translation of guide/composition-api-template-refs
1 parent 5e33c72 commit d4f1897

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/guide/composition-api-template-refs.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Template Refs
1+
# _refs_ de Template
22

3-
> This section uses [single-file component](single-file-component.html) syntax for code examples
3+
> Esta seção usa a sintaxe de [componente single-file](single-file-component.html) para exemplos de código
44
5-
> This guide assumes that you have already read the [Composition API Introduction](composition-api-introduction.html) and [Reactivity Fundamentals](reactivity-fundamentals.html). Read that first if you are new to Composition API.
5+
> Este guia pressupõe que você já leu a [Introdução à API de Composição](composition-api-introduction.html) e os [Fundamentos da Reatividade](reactivity-fundamentals.html). Leia lá primeiro se você for novo na API de Composição.
66
7-
When using the Composition API, the concept of [reactive refs](reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs) and [template refs](component-template-refs.html) are unified. In order to obtain a reference to an in-template element or component instance, we can declare a ref as usual and return it from [setup()](composition-api-setup.html):
7+
Ao usar a API de Composição, os conceitos de [_refs_ reativos](reactivity-fundamentals.html#criacao-de-valores-reativos-avulsos-como-refs) e [_refs_ de _template_](component-template-refs.html) são unificados. Para obter uma referência a um elemento do _template_ ou instância de componente, podemos declarar uma referência como de costume e retorná-la de [setup()](composition-api-setup.html):
88

99
```html
1010
<template>
11-
<div ref="root">This is a root element</div>
11+
<div ref="root">Este é um elemento raiz</div>
1212
</template>
1313

1414
<script>
@@ -19,8 +19,8 @@ When using the Composition API, the concept of [reactive refs](reactivity-fundam
1919
const root = ref(null)
2020
2121
onMounted(() => {
22-
// the DOM element will be assigned to the ref after initial render
23-
console.log(root.value) // <div>This is a root element</div>
22+
// o elemento DOM será atribuído ao ref após a renderização inicial
23+
console.log(root.value) // <div>Este é um elemento raiz</div>
2424
})
2525
2626
return {
@@ -31,11 +31,11 @@ When using the Composition API, the concept of [reactive refs](reactivity-fundam
3131
</script>
3232
```
3333

34-
Here we are exposing `root` on the render context and binding it to the div as its ref via `ref="root"`. In the Virtual DOM patching algorithm, if a VNode's `ref` key corresponds to a ref on the render context, the VNode's corresponding element or component instance will be assigned to the value of that ref. This is performed during the Virtual DOM mount / patch process, so template refs will only get assigned values after the initial render.
34+
Aqui estamos expondo `root` no contexto de renderização e vinculando-o a div como sua referência via `ref="root"`. No algoritmo de correção (_patch_) do DOM Virtual, se a chave `ref` de um VNode corresponder a uma referência no contexto de renderização, o elemento ou instância de componente correspondente do VNode será atribuído ao valor dessa referência. Isso é realizado durante o processo de montagem / _patch_ do Virtual DOM, portanto, as referências do _template_ só receberão valores atribuídos após a renderização inicial.
3535

36-
Refs used as templates refs behave just like any other refs: they are reactive and can be passed into (or returned from) composition functions.
36+
Referências usadas como _refs_ de _template_ se comportam como quaisquer outras _refs_: elas são reativas e podem ser passadas (ou retornadas) a funções de composição.
3737

38-
## Usage with JSX
38+
## Uso com JSX
3939

4040
```js
4141
export default {
@@ -47,15 +47,15 @@ export default {
4747
ref: root
4848
})
4949

50-
// with JSX
50+
// com JSX
5151
return () => <div ref={root} />
5252
}
5353
}
5454
```
5555

56-
## Usage inside `v-for`
56+
## Uso dentro de `v-for`
5757

58-
Composition API template refs do not have special handling when used inside `v-for`. Instead, use function refs to perform custom handling:
58+
As _refs_ de _template_ da API de Composição não têm tratamento especial quando usadas dentro de `v-for`. Em vez disso, use a sintaxe de função nas _refs_ para realizar um tratamento personalizado:
5959

6060
```html
6161
<template>
@@ -72,7 +72,7 @@ Composition API template refs do not have special handling when used inside `v-f
7272
const list = reactive([1, 2, 3])
7373
const divs = ref([])
7474
75-
// make sure to reset the refs before each update
75+
// certifique-se de limpar as refs antes de cada atualização
7676
onBeforeUpdate(() => {
7777
divs.value = []
7878
})
@@ -86,15 +86,15 @@ Composition API template refs do not have special handling when used inside `v-f
8686
</script>
8787
```
8888

89-
## Watching Template Refs
89+
## Observando _refs_ de Templates
9090

91-
Watching a template ref for changes can be an alternative to the use of lifecycle hooks that was demonstrated in the previous examples.
91+
Observar uma referência de _template_ por alterações pode ser uma alternativa ao uso de gatilhos de ciclo de vida que foi demonstrado nos exemplos anteriores.
9292

93-
But a key difference to lifecycle hooks is that `watch()` and `watchEffect()` effects are run *before* the DOM is mounted or updated so the template ref hasn't been updated when the watcher runs the effect:
93+
Mas uma diferença chave para os gatilhos do ciclo de vida é que os efeitos `watch()` e `watchEffect()` são executados *antes* do DOM ser montado ou atualizado, de modo que o _ref_ de _template_ ainda não foi atualizado quando o observador executa o efeito:
9494

9595
```vue
9696
<template>
97-
<div ref="root">This is a root element</div>
97+
<div ref="root">Este é um elemento raiz</div>
9898
</template>
9999
100100
<script>
@@ -105,8 +105,8 @@ But a key difference to lifecycle hooks is that `watch()` and `watchEffect()` ef
105105
const root = ref(null)
106106
107107
watchEffect(() => {
108-
// This effect runs before the DOM is updated, and consequently,
109-
// the template ref does not hold a reference to the element yet.
108+
// Este efeito é executado antes que o DOM seja atualizado e, consequentemente,
109+
// o ref de template ainda não contém uma referência ao elemento.
110110
console.log(root.value) // => null
111111
})
112112
@@ -118,11 +118,11 @@ But a key difference to lifecycle hooks is that `watch()` and `watchEffect()` ef
118118
</script>
119119
```
120120

121-
Therefore, watchers that use template refs should be defined with the `flush: 'post'` option. This will run the effect *after* the DOM has been updated and ensure that the template ref stays in sync with the DOM and references the correct element.
121+
Portanto, observadores que usam _refs_ de _template_ devem ser definidos com a opção `flush: 'post'`. Isso executará o efeito *depois* do DOM ser atualizado e garantirá que o _ref_ de _template_ permaneça em sincronia com o DOM e faça referência ao elemento correto.
122122

123123
```vue
124124
<template>
125-
<div ref="root">This is a root element</div>
125+
<div ref="root">Este é um elemento raiz</div>
126126
</template>
127127
128128
<script>
@@ -133,7 +133,7 @@ Therefore, watchers that use template refs should be defined with the `flush: 'p
133133
const root = ref(null)
134134
135135
watchEffect(() => {
136-
console.log(root.value) // => <div>This is a root element</div>
136+
console.log(root.value) // => <div>Este é um elemento raiz</div>
137137
},
138138
{
139139
flush: 'post'
@@ -147,4 +147,4 @@ Therefore, watchers that use template refs should be defined with the `flush: 'p
147147
</script>
148148
```
149149

150-
* See also: [Computed and Watchers](./reactivity-computed-watchers.html#effect-flush-timing)
150+
* Ver também: [Dados Computados e Observadores](./reactivity-computed-watchers.html#effect-flush-timing)

0 commit comments

Comments
 (0)