Skip to content

Commit 80017fc

Browse files
committed
Docs: translate composition-api-setup
1 parent f6a152a commit 80017fc

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

src/guide/composition-api-setup.md

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
# Setup
1+
# Configuração
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 de um arquivo](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 assume que você já leu a [Introdução à API de Composição](composition-api-introduction.html) e [Fundamentos de Reatividade](reactivity-fundamentals.html). Leia-os primeiros se você é novo à API de composição (Composition API).
66
7-
## Arguments
7+
## Argumentos
88

9-
When using the `setup` function, it will take two arguments:
9+
Ao usar a função `setup`, ela receberá dois argumentos:
1010

1111
1. `props`
1212
2. `context`
13-
14-
Let's dive deeper into how each argument can be used.
13+
14+
Vamos nos aprofundar em como cada argumento pode ser usado.
1515

1616
### Props
1717

18-
The first argument in the `setup` function is the `props` argument. Just as you would expect in a standard component, `props` inside of a `setup` function are reactive and will be updated when new props are passed in.
18+
O primeiro argumento da função `setup` é o argumento `props`. Assim como é de se esperar em um componente padrão, `props` dentro de uma função `setup` são reativos e serão atualizados quando novos props são passados.
19+
1920

2021
```js
2122
// MyBook.vue
@@ -29,12 +30,11 @@ export default {
2930
}
3031
}
3132
```
32-
3333
:::warning
34-
However, because `props` are reactive, you **cannot use ES6 destructuring** because it will remove props reactivity.
34+
No entanto, porque os `props` são reativos, você **não pode usar desestruturação de objetos com ES6** porque isso vai remover sua reatividade.
3535
:::
3636

37-
If you need to destructure your props, you can do this safely by utilizing the [toRefs](reactivity-fundamentals.html#destructuring-reactive-state) inside of the `setup` function.
37+
Se você precisa desestruturar seus props, você o pode fazer seguramente usando o [toRefs](reactivity-fundamentals.html#destructuring-reactive-state) dentro da função `setup`.
3838

3939
```js
4040
// MyBook.vue
@@ -47,10 +47,10 @@ setup(props) {
4747
console.log(title.value)
4848
}
4949
```
50+
### Contexto
5051

51-
### Context
52+
O segundo argumento passado para a função `setup` é o `contexto`. O `contexto` é um objeto Javascript normal que expõe três propriedades do componente:
5253

53-
The second argument passed to the `setup` function is the `context`. The `context` is a normal JavaScript object that exposes three component properties:
5454

5555
```js
5656
// MyBook.vue
@@ -69,7 +69,7 @@ export default {
6969
}
7070
```
7171

72-
The `context` object is a normal JavaScript object, i.e., it is not reactive, this means you can safely use ES6 destructuring on `context`.
72+
O objeto `contexto` é um objeto normal Javascript (ou seja, não é reativo, o que significa que você pode seguramente utilizar a desestruturação ES6 nele)
7373

7474
```js
7575
// MyBook.vue
@@ -79,60 +79,60 @@ export default {
7979
}
8080
}
8181
```
82+
`attrs` e `slots` são objetos com estados que sempre são atualizados quando o componente é atualizado. Isso significa que você deve evitar desestruturá-los e sempre referenciar suas propriedades por meio de `attrs.x` ou `slots.x`. Note também que, diferente de `props`, `attrs` e `slots` não são reativos. Se você busca aplicar efeitos baseados em mudanças nos `attrs` ou `slots`, você deveria fazê-lo dentro do hook de ciclo de vida `onUpdate`.
8283

83-
`attrs` and `slots` are stateful objects that are always updated when the component itself is updated. This means you should avoid destructuring them and always reference properties as `attrs.x` or `slots.x`. Also note that unlike `props`, `attrs` and `slots` are **not** reactive. If you intend to apply side effects based on `attrs` or `slots` changes, you should do so inside an `onUpdated` lifecycle hook.
84-
85-
## Accessing Component Properties
84+
## Accessando propriedades de componentes
8685

87-
When `setup` is executed, the component instance has not been created yet. As a result, you will only be able to access the following properties:
86+
Quando o `setup` é executado, a instância do componente ainda não foi criada. Como resultado, você somente poderá acessar as seguintes propriedades:
8887

8988
- `props`
9089
- `attrs`
9190
- `slots`
9291
- `emit`
9392

94-
In other words, you **will not have access** to the following component options:
93+
Em outras palavras, você **não terá acesso** às seguintes opções de componentes:
9594

9695
- `data`
9796
- `computed`
9897
- `methods`
9998

100-
## Usage with Templates
99+
## Usos com os Templates
100+
101+
Se `setup` retorna um objeto, as propriedades no objeto podem ser acessadas no template do componente, assim como as propriedades do `props` passadas para o `setup`:
101102

102103
If `setup` returns an object, the properties on the object can be accessed in the component's template, as well as the properties of the `props` passed into `setup`:
103104

104105
```vue-html
105106
<!-- MyBook.vue -->
106107
<template>
107-
<div>{{ collectionName }}: {{ readersNumber }} {{ book.title }}</div>
108+
<div>{{ nomeDaColecao }}: {{ numeroDeLeitores }} {{ livro.titulo }}</div>
108109
</template>
109110
110111
<script>
111112
import { ref, reactive } from 'vue'
112113
113114
export default {
114115
props: {
115-
collectionName: String
116+
nomeDaColecao: String
116117
},
117118
setup(props) {
118-
const readersNumber = ref(0)
119-
const book = reactive({ title: 'Vue 3 Guide' })
119+
const numeroDeLeitores = ref(0)
120+
const livro = reactive({ titulo: 'Vue 3 Guide' })
120121
121122
// expose to template
122123
return {
123-
readersNumber,
124-
book
124+
numeroDeLeitores,
125+
livro
125126
}
126127
}
127128
}
128129
</script>
129130
```
131+
Note que [refs](../api/refs-api.html#ref) que é retornado do `setup` é [automaticamente desestruturado](/guide/reactivity-fundamentals.html#ref-unwrapping) quando acessado no template, portanto você não deveria usar `.value` nos templates.
130132

131-
Note that [refs](../api/refs-api.html#ref) returned from `setup` are [automatically unwrapped](/guide/reactivity-fundamentals.html#ref-unwrapping) when accessed in the template so you shouldn't use `.value` in templates.
132-
133-
## Usage with Render Functions
133+
## Uso com funções de renderização
134134

135-
`setup` can also return a render function which can directly make use of the reactive state declared in the same scope:
135+
`setup` pode, inclusive, retornar uma função de renderização que pode diretamente fazer uso do estado reativo declarado no mesmo escopo:
136136

137137
```js
138138
// MyBook.vue
@@ -141,14 +141,13 @@ import { h, ref, reactive } from 'vue'
141141

142142
export default {
143143
setup() {
144-
const readersNumber = ref(0)
145-
const book = reactive({ title: 'Vue 3 Guide' })
146-
// Please note that we need to explicitly expose ref value here
147-
return () => h('div', [readersNumber.value, book.title])
144+
const numeroDeLeitores = ref(0)
145+
const livro = reactive({ titulo: 'Vue 3 Guide' })
146+
// Por favor, note que precisamos explicitamente expor o valor de ref aqui
147+
return () => h('div', [readersNumber.value, book.titulo])
148148
}
149149
}
150150
```
151+
# Uso de `this`
151152

152-
## Usage of `this`
153-
154-
**Inside `setup()`, `this` won't be a reference to the current active instance** Since `setup()` is called before other component options are resolved, `this` inside `setup()` will behave quite differently from `this` in other options. This might cause confusions when using `setup()` along other Options API.
153+
**Dentro de `setup()`, `this` não será uma referência à instância atualmente ativa**. Já que `setup()` é chamado antes que as outras opções do componente são resolvidas, `this` dentro de `setup()` vai se comportar diferentemente do `this` noutras opções. Isso pode causar confusões ao se usar o `setup()` com outras API de Opções.

0 commit comments

Comments
 (0)