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/api/refs-api.md
+33-33Lines changed: 33 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Refs
2
2
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
4
4
5
5
## `ref`
6
6
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
8
8
9
-
**Example:**
9
+
**Exemplo:**
10
10
11
11
```js
12
12
constcount=ref(0)
@@ -16,9 +16,9 @@ count.value++
16
16
console.log(count.value) // 1
17
17
```
18
18
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).
20
20
21
-
**Typing:**
21
+
**Tipando:**
22
22
23
23
```ts
24
24
interfaceRef<T> {
@@ -28,36 +28,36 @@ interface Ref<T> {
28
28
function ref<T>(value:T):Ref<T>
29
29
```
30
30
31
-
Sometimeswemayneedtospecifycomplextypesforaref's inner value. We can do that succinctly by passing a generics argument when calling `ref` to override the default inference:
Retornaovalorinternoseoargumentoforum [`ref`](#ref), casocontrário, retornaopróprioargumento. Esta é uma"sugar function"para`val = isRef(val) ? val.value : val`.
51
51
52
52
```js
53
53
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
55
55
}
56
56
```
57
57
58
58
## `toRef`
59
59
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.
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
+
Converteumobjetoreativoemumobjetosimplesondecadapropriedadedoobjetoresultante é um[`ref`](#ref) apontandoparaapropriedadecorrespondentedoobjetooriginal.
90
90
91
91
```js
92
92
const state = reactive({
@@ -96,23 +96,23 @@ const state = reactive({
96
96
97
97
const stateAsRefs = toRefs(state)
98
98
/*
99
-
Type of stateAsRefs:
99
+
Tipo de stateAsRefs:
100
100
101
101
{
102
102
foo: Ref<number>,
103
103
bar: Ref<number>
104
104
}
105
105
*/
106
106
107
-
//The ref and the original property is "linked"
107
+
// O ref e a propriedade original estão "vinculados"
108
108
state.foo++
109
109
console.log(stateAsRefs.foo.value) // 2
110
110
111
111
stateAsRefs.foo.value++
112
112
console.log(state.foo) // 3
113
113
```
114
114
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:
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`.
0 commit comments