Skip to content

Commit a612510

Browse files
author
Lucas Castro
committed
Traduzir api/refs-api
1 parent b89c932 commit a612510

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/api/refs-api.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Refs
22

3-
> This section uses [single-file component](../guide/single-file-component.html) syntax for code examples
3+
> Esta seção usa a sintaxe [single-file component](../guide/single-file-component.html) para os exemplos de código
44
55
## `ref`
66

7-
Takes an inner value and returns a reactive and mutable ref object. The ref object has a single property `.value` that points to the inner value.
7+
Assume um valor interno e retorna um objeto "ref" reativo e mutável. O objeto "ref" tem uma única propriedade `.value` que aponta para o valor interno
88

9-
**Example:**
9+
**Exemplo:**
1010

1111
```js
1212
const count = ref(0)
@@ -16,9 +16,9 @@ count.value++
1616
console.log(count.value) // 1
1717
```
1818

19-
If an object is assigned as a ref's value, the object is made deeply reactive by the [reactive](./basic-reactivity.html#reactive) method.
19+
Se um objeto for atribuído como um valor "ref", o objeto se tornará profundamente reativo pelo método [reativo](./basic-reactivity.html#reactive).
2020

21-
**Typing:**
21+
**Tipando:**
2222

2323
```ts
2424
interface Ref<T> {
@@ -28,36 +28,36 @@ interface Ref<T> {
2828
function ref<T>(value: T): Ref<T>
2929
```
3030

31-
Sometimes we may need to specify complex types for a ref's inner value. We can do that succinctly by passing a generics argument when calling `ref` to override the default inference:
31+
Às vezes, podemos precisar especificar tipos complexos para o valor interno de um "ref". Podemos fazer isso de forma sucinta passando um argumento genérico ao chamar `ref` para substituir a inferência padrão:
3232

3333
```ts
34-
const foo = ref<string | number>('foo') // foo's type: Ref<string | number>
34+
const foo = ref<string | number>('foo') // tipo foo: Ref<string | number>
3535
3636
foo.value = 123 // ok!
3737
```
3838

39-
If the type of the generic is unknown, it's recommended to cast `ref` to `Ref<T>`:
39+
Se o tipo da "generic" for desconhecido, é recomendado converter `ref` em` Ref<T>`:
4040

4141
```js
4242
function useState<State extends string>(initial: State) {
43-
const state = ref(initial) as Ref<State> // state.value -> State extends string
43+
const state = ref(initial) as Ref<State> // state.value -> State estende string
4444
return state
4545
}
4646
```
4747

4848
## `unref`
4949

50-
Returns the inner value if the argument is a [`ref`](#ref), otherwise return the argument itself. This is a sugar function for `val = isRef(val) ? val.value : val`.
50+
Retorna o valor interno se o argumento for um [`ref`](#ref), caso contrário, retorna o próprio argumento. Esta é uma "sugar function" para `val = isRef(val) ? val.value : val`.
5151

5252
```js
5353
function useFoo(x: number | Ref<number>) {
54-
const unwrapped = unref(x) // unwrapped is guaranteed to be number now
54+
const unwrapped = unref(x) // unwrapped é garantido ser number agora
5555
}
5656
```
5757

5858
## `toRef`
5959

60-
Can be used to create a [`ref`](#ref) for a property on a source reactive object. The ref can then be passed around, retaining the reactive connection to its source property.
60+
Pode ser usado para criar um [`ref`](#ref) para uma propriedade em um objeto reativo de origem. O "ref" pode então ser passado, mantendo a conexão reativa com sua propriedade de origem.
6161

6262
```js
6363
const state = reactive({
@@ -74,7 +74,7 @@ state.foo++
7474
console.log(fooRef.value) // 3
7575
```
7676

77-
`toRef` is useful when you want to pass the ref of a prop to a composition function:
77+
`toRef` é útil quando você deseja passar o "ref" de um objeto para uma função de composição:
7878

7979
```js
8080
export default {
@@ -86,7 +86,7 @@ export default {
8686

8787
## `toRefs`
8888

89-
Converts a reactive object to a plain object where each property of the resulting object is a [`ref`](#ref) pointing to the corresponding property of the original object.
89+
Converte um objeto reativo em um objeto simples onde cada propriedade do objeto resultante é um [`ref`](#ref) apontando para a propriedade correspondente do objeto original.
9090

9191
```js
9292
const state = reactive({
@@ -96,23 +96,23 @@ const state = reactive({
9696
9797
const stateAsRefs = toRefs(state)
9898
/*
99-
Type of stateAsRefs:
99+
Tipo de stateAsRefs:
100100
101101
{
102102
foo: Ref<number>,
103103
bar: Ref<number>
104104
}
105105
*/
106106
107-
// The ref and the original property is "linked"
107+
// O ref e a propriedade original estão "vinculados"
108108
state.foo++
109109
console.log(stateAsRefs.foo.value) // 2
110110
111111
stateAsRefs.foo.value++
112112
console.log(state.foo) // 3
113113
```
114114

115-
`toRefs` is useful when returning a reactive object from a composition function so that the consuming component can destructure/spread the returned object without losing reactivity:
115+
`toRefs` é útil ao retornar um objeto reativo de uma função de composição para que o componente de consumo possa desestruturar/espalhar o objeto retornado sem perder a reatividade:
116116

117117
```js
118118
function useFeatureX() {
@@ -121,15 +121,15 @@ function useFeatureX() {
121121
bar: 2
122122
})
123123
124-
// logic operating on state
124+
// lógica operando no estado
125125
126-
// convert to refs when returning
126+
// converter para "refs" ao retornar
127127
return toRefs(state)
128128
}
129129
130130
export default {
131131
setup() {
132-
// can destructure without losing reactivity
132+
// pode-se desestruturar sem perder a reatividade
133133
const { foo, bar } = useFeatureX()
134134
135135
return {
@@ -142,13 +142,13 @@ export default {
142142

143143
## `isRef`
144144

145-
Checks if a value is a ref object.
145+
Verifica se um valor é um objeto "ref".
146146

147147
## `customRef`
148148

149-
Creates a customized ref with explicit control over its dependency tracking and updates triggering. It expects a factory function, which receives `track` and `trigger` functions as arguments and should return an object with `get` and `set`.
149+
Cria uma "ref" personalizada com controle explícito sobre seu rastreamento de dependência e acionamento de atualizações. Ele espera uma função de fábrica, que recebe as funções `track` e` trigger` como argumentos e deve retornar um objeto com `get` e` set`.
150150

151-
- Example using a custom ref to implement debounce with `v-model`:
151+
- Exemplo usando uma "ref" personalizada para implementar debounce (prática que visa diminuir a quantidade de eventos disparados) com `v-model`:
152152

153153
```html
154154
<input v-model="text" />
@@ -183,7 +183,7 @@ Creates a customized ref with explicit control over its dependency tracking and
183183
}
184184
```
185185

186-
**Typing:**
186+
**Tipando:**
187187

188188
```ts
189189
function customRef<T>(factory: CustomRefFactory<T>): Ref<T>
@@ -199,7 +199,7 @@ type CustomRefFactory<T> = (
199199

200200
## `shallowRef`
201201

202-
Creates a ref that tracks its own `.value` mutation but doesn't make its value reactive.
202+
Cria uma "ref" que rastreia sua própria mutação `.value`, mas não torna seu valor reativo.
203203

204204
```js
205205
const foo = shallowRef({})
@@ -209,27 +209,27 @@ foo.value = {}
209209
isReactive(foo.value) // false
210210
```
211211

212-
**See also**: [Creating Standalone Reactive Values as `refs`](../guide/reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs)
212+
**Veja também**: [Criação de valores reativos autônomos como `refs`](../guide/reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs)
213213

214214
## `triggerRef`
215215

216-
Execute any effects tied to a [`shallowRef`](#shallowref) manually.
216+
Execute quaisquer efeitos vinculados a um [`shallowRef`](#shallowref) manualmente.
217217

218218
```js
219219
const shallow = shallowRef({
220-
greet: 'Hello, world'
220+
greet: 'Olá, mundo!'
221221
})
222222
223-
// Logs "Hello, world" once for the first run-through
223+
// Mostra "Olá, mundo!" uma vez para a primeira execução
224224
watchEffect(() => {
225225
console.log(shallow.value.greet)
226226
})
227227
228-
// This won't trigger the effect because the ref is shallow
229-
shallow.value.greet = 'Hello, universe'
228+
// Isso não acionará o efeito porque o "ref" é shallow
229+
shallow.value.greet = 'Olá, universo!'
230230
231-
// Logs "Hello, universe"
231+
// Mostra "Olá, universo!"
232232
triggerRef(shallow)
233233
```
234234

235-
**See also:** [Computed and Watch - watchEffect](./computed-watch-api.html#watcheffect)
235+
**Veja também:** [Computado e Assistido - watchEffect](./computed-watch-api.html#watcheffect)

0 commit comments

Comments
 (0)