Skip to content

Commit c40ab61

Browse files
authored
Merge pull request #188 from teffybiskup/patch-5
Translate "guide/composition-api-provide-inject.md"
2 parents 8d7d122 + 99fd18f commit c40ab61

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/guide/composition-api-provide-inject.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Provide / Inject
1+
# Prover e Injetar Dados
22

3-
> This guide assumes that you have already read [Provide / Inject](component-provide-inject.html), [Composition API Introduction](composition-api-introduction.html), and [Reactivity Fundamentals](reactivity-fundamentals.html).
3+
> Este guia assume que você já leu as seções [Prover e Injetar Dados](component-provide-inject.html), [Introdução a API de Composição](composition-api-introduction.html) e [Fundamentos de Reatividade](reactivity-fundamentals.html).
44
5-
We can use [provide / inject](component-provide-inject.html) with the Composition API as well. Both can only be called during [`setup()`](composition-api-setup.html) with a current active instance.
5+
Podemos [prover e injetar dados](component-provide-inject.html) com a API de Composição também. Ambos só podem ser chamados durante [`setup()`](composition-api-setup.html) com uma instância ativa atual.
66

7-
## Scenario Background
7+
## Exemplo de Cenário
88

9-
Let's assume that we want to rewrite the following code, which contains a `MyMap` component that provides a `MyMarker` component with the user's location, using the Composition API.
9+
Vamos supor que queremos reescrever o código a seguir, que contém um componente `MyMap` que provê um componente `MyMarker` com a localização do usuário, usando a API de Composição.
1010

1111
```vue
1212
<!-- src/components/MyMap.vue -->
@@ -22,7 +22,7 @@ export default {
2222
MyMarker
2323
},
2424
provide: {
25-
location: 'North Pole',
25+
location: 'Polo Norte',
2626
geolocation: {
2727
longitude: 90,
2828
latitude: 135
@@ -41,16 +41,16 @@ export default {
4141
</script>
4242
```
4343

44-
## Using Provide
44+
## Usando Provide
4545

46-
When using `provide` in `setup()`, we start by explicitly importing the method from `vue`. This allows us to define each property with its own invocation of `provide`.
46+
Ao usar `provide` no `setup()`, começamos importando explicitamente o método de `vue`. Isso nos permite definir cada propriedade com sua própria invocação de `provide`.
4747

48-
The `provide` function allows you to define the property through two parameters:
48+
A função `provide` permite definir a propriedade por meio de dois parâmetros:
4949

50-
1. The property's name (`<String>` type)
51-
2. The property's value
50+
1. O nome da propriedade (do tipo `<String>`); e
51+
2. O valor da propriedade.
5252

53-
Using our `MyMap` component, our provided values can be refactored as the following:
53+
Usando nosso componente `MyMap`, nossos valores providos podem ser refatorados da seguinte forma:
5454

5555
```vue{7,14-20}
5656
<!-- src/components/MyMap.vue -->
@@ -67,7 +67,7 @@ export default {
6767
MyMarker
6868
},
6969
setup() {
70-
provide('location', 'North Pole')
70+
provide('location', 'Polo Norte')
7171
provide('geolocation', {
7272
longitude: 90,
7373
latitude: 135
@@ -77,16 +77,16 @@ export default {
7777
</script>
7878
```
7979

80-
## Using Inject
80+
## Usando Inject
8181

82-
When using `inject` in `setup()`, we also need to explicitly import it from `vue`. Once we do so, this allows us to invoke it to define how we want to expose it to our component.
82+
Ao usar `inject` no `setup()`, também precisamos importá-lo explicitamente de `vue`. Assim que fizermos isso, isso nos permitirá invocá-lo para definir como queremos expô-lo ao nosso componente.
8383

84-
The `inject` function takes two parameters:
84+
A função `inject` leva dois parâmetros:
8585

86-
1. The name of the property to inject
87-
2. A default value (**Optional**)
86+
1. O nome da propriedade a injetar; e
87+
2. Um valor padrão (**Opcional**).
8888

89-
Using our `MyMarker` component, we can refactor it with the following code:
89+
Usando nosso componente `MyMarker`, podemos refatorá-lo com o seguinte código:
9090

9191
```vue{3,6-14}
9292
<!-- src/components/MyMarker.vue -->
@@ -95,7 +95,7 @@ import { inject } from 'vue'
9595
9696
export default {
9797
setup() {
98-
const userLocation = inject('location', 'The Universe')
98+
const userLocation = inject('location', 'O Universo')
9999
const userGeolocation = inject('geolocation')
100100
101101
return {
@@ -107,13 +107,13 @@ export default {
107107
</script>
108108
```
109109

110-
## Reactivity
110+
## Reatividade
111111

112-
### Adding Reactivity
112+
### Adicionando Reatividade
113113

114-
To add reactivity between provided and injected values, we can use a [ref](reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs) or [reactive](reactivity-fundamentals.html#declaring-reactive-state) when providing a value.
114+
Para adicionar reatividade entre os valores providos e injetados, podemos usar uma [ref](reactivity-fundamentals.html#criacao-de-valores-reativos-avulsos-como-refs) ou [reactive](reactivity-fundamentals.html#declarando-estado-reativo) ao prover um valor.
115115

116-
Using our `MyMap` component, our code can be updated as follows:
116+
Usando nosso componente `MyMap`, nosso código pode ser atualizado da seguinte forma:
117117

118118
```vue{7,15-22}
119119
<!-- src/components/MyMap.vue -->
@@ -130,7 +130,7 @@ export default {
130130
MyMarker
131131
},
132132
setup() {
133-
const location = ref('North Pole')
133+
const location = ref('Polo Norte')
134134
const geolocation = reactive({
135135
longitude: 90,
136136
latitude: 135
@@ -143,13 +143,13 @@ export default {
143143
</script>
144144
```
145145

146-
Now, if anything changes in either property, the `MyMarker` component will automatically be updated as well!
146+
Agora, se alguma coisa mudar em qualquer uma das propriedades, o componente `MyMarker` também será atualizado automaticamente!
147147

148-
### Mutating Reactive Properties
148+
### Mutando Propriedades Reativas
149149

150-
When using reactive provide / inject values, **it is recommended to keep any mutations to reactive properties inside of the _provider_ whenever possible**.
150+
Ao usar dados providos e injetados reativos, **é recomendado manter quaisquer mutações nas propriedades reativas dentro do _provider_ sempre que possível**.
151151

152-
For example, in the event we needed to change the user's location, we would ideally do this inside of our `MyMap` component.
152+
Por exemplo, no caso de precisarmos alterar a localização do usuário, o ideal seria fazer isso dentro de nosso componente `MyMap`.
153153

154154
```vue{28-32}
155155
<!-- src/components/MyMap.vue -->
@@ -166,7 +166,7 @@ export default {
166166
MyMarker
167167
},
168168
setup() {
169-
const location = ref('North Pole')
169+
const location = ref('Polo Norte')
170170
const geolocation = reactive({
171171
longitude: 90,
172172
latitude: 135
@@ -181,14 +181,14 @@ export default {
181181
},
182182
methods: {
183183
updateLocation() {
184-
this.location = 'South Pole'
184+
this.location = 'Polo Sul'
185185
}
186186
}
187187
}
188188
</script>
189189
```
190190

191-
However, there are times where we need to update the data inside of the component where the data is injected. In this scenario, we recommend providing a method that is responsible for mutating the reactive property.
191+
No entanto, há momentos em que precisamos atualizar os dados dentro do componente onde os dados são injetados. Nesse cenário, recomendamos prover um método que seja responsável por mutar a propriedade reativa.
192192

193193
```vue{21-23,27}
194194
<!-- src/components/MyMap.vue -->
@@ -205,14 +205,14 @@ export default {
205205
MyMarker
206206
},
207207
setup() {
208-
const location = ref('North Pole')
208+
const location = ref('Polo Norte')
209209
const geolocation = reactive({
210210
longitude: 90,
211211
latitude: 135
212212
})
213213
214214
const updateLocation = () => {
215-
location.value = 'South Pole'
215+
location.value = 'Polo Sul'
216216
}
217217
218218
provide('location', location)
@@ -230,7 +230,7 @@ import { inject } from 'vue'
230230
231231
export default {
232232
setup() {
233-
const userLocation = inject('location', 'The Universe')
233+
const userLocation = inject('location', 'O Universo')
234234
const userGeolocation = inject('geolocation')
235235
const updateUserLocation = inject('updateLocation')
236236
@@ -244,7 +244,7 @@ export default {
244244
</script>
245245
```
246246

247-
Finally, we recommend using `readonly` on provided property if you want to ensure that the data passed through `provide` cannot be mutated by the injected component.
247+
Por fim, recomendamos o uso de `readonly` na propriedade provida, se você quiser garantir que os dados passados por `provide` não possam sofrer mutação pelo componente injetado.
248248

249249
```vue{7,25-26}
250250
<!-- src/components/MyMap.vue -->
@@ -261,14 +261,14 @@ export default {
261261
MyMarker
262262
},
263263
setup() {
264-
const location = ref('North Pole')
264+
const location = ref('Polo Norte')
265265
const geolocation = reactive({
266266
longitude: 90,
267267
latitude: 135
268268
})
269269
270270
const updateLocation = () => {
271-
location.value = 'South Pole'
271+
location.value = 'Polo Sul'
272272
}
273273
274274
provide('location', readonly(location))

0 commit comments

Comments
 (0)