Skip to content

Commit d634ddc

Browse files
authored
Merge pull request #39 from Wiriyamu/docs/dynamic-async
docs: Translate file component-dynamic-async
2 parents efbe0d7 + b49dce5 commit d634ddc

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

src/guide/component-dynamic-async.md

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,41 @@
1-
# Dynamic & Async Components
1+
# Dinâmicos & Assíncronos
22

3-
> This page assumes you've already read the [Components Basics](component-basics.md). Read that first if you are new to components.
3+
> Essa página assume que você já leu o [Básico sobre Componentes](component-basics.md). Leia lá primeiro se você for novo em componentes.
44
5-
## Dynamic Components with `keep-alive`
5+
## Componentes Dinâmicos com `keep-alive`
66

7-
Earlier, we used the `is` attribute to switch between components in a tabbed interface:
7+
Anteriormente, usamos o atributo `is` para alternar entre os componentes em uma interface com guias:
88

99
```vue-html
1010
<component :is="currentTabComponent"></component>
1111
```
1212

13-
When switching between these components though, you'll sometimes want to maintain their state or avoid re-rendering for performance reasons. For example, when expanding our tabbed interface a little:
13+
Ao alternar entre esses componentes, às vezes, você desejará manter seu estado ou evitar uma nova renderização, por motivos de desempenho. Por exemplo, ao expandir nossa interface com guias um pouco:
1414

15-
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="html,result" data-user="Vue" data-slug-hash="jOPjZOe" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Dynamic components: without keep-alive">
16-
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/jOPjZOe">
17-
Dynamic components: without keep-alive</a> by Vue (<a href="https://codepen.io/Vue">@Vue</a>)
18-
on <a href="https://codepen.io">CodePen</a>.</span>
19-
</p>
20-
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
15+
<common-codepen-snippet title="Componentes Dinâmicos: sem keep-alive" slug="jOPjZOe" />
2116

22-
You'll notice that if you select a post, switch to the _Archive_ tab, then switch back to _Posts_, it's no longer showing the post you selected. That's because each time you switch to a new tab, Vue creates a new instance of the `currentTabComponent`.
17+
Você notará que, se selecionar uma postagem, alternar para a guia _Arquivo_ e, em seguida, voltar para _Postagens_, ela não estará mais mostrando a postagem selecionada. Isso acontece pois, cada vez que você muda para uma nova guia, o Vue cria uma nova instância do componente `currentTabComponent`.
2318

24-
Recreating dynamic components is normally useful behavior, but in this case, we'd really like those tab component instances to be cached once they're created for the first time. To solve this problem, we can wrap our dynamic component with a `<keep-alive>` element:
19+
Recriar componentes dinâmicos normalmente é um comportamento útil, mas, nesse caso, gostaríamos que essas instâncias de componentes de guias fossem armazenadas em _cache_ assim que fossem criadas pela primeira vez. Para resolver este problema, podemos envolver nosso componente dinâmico com um elemento `<keep-alive>`:
2520

2621
```vue-html
27-
<!-- Inactive components will be cached! -->
22+
<!-- Componentes inativos serão armazenados em cache -->
2823
<keep-alive>
2924
<component :is="currentTabComponent"></component>
3025
</keep-alive>
3126
```
3227

33-
Check out the result below:
28+
Confira o resultado abaixo:
3429

35-
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="html,result" data-user="Vue" data-slug-hash="VwLJQvP" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Dynamic components: with keep-alive">
36-
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/VwLJQvP">
37-
Dynamic components: with keep-alive</a> by Vue (<a href="https://codepen.io/Vue">@Vue</a>)
38-
on <a href="https://codepen.io">CodePen</a>.</span>
39-
</p>
40-
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
30+
<common-codepen-snippet title="Componentes Dinâmicos: com keep-alive" slug="VwLJQvP" />
4131

42-
Now the _Posts_ tab maintains its state (the selected post) even when it's not rendered.
32+
Agora, a guia _Postagens_ mantém seu estado (a postagem selecionada) mesmo quando não é renderizada.
4333

44-
Check out more details on `<keep-alive>` in the [API reference](../api/built-in-components.html#keep-alive).
34+
Confira mais detalhes sobre `<keep-alive>` em [Referências de API](../api/built-in-components.html#keep-alive).
4535

46-
## Async Components
36+
## Componentes Assíncronos
4737

48-
In large applications, we may need to divide the app into smaller chunks and only load a component from the server when it's needed. To make that possible, Vue has a `defineAsyncComponent` method:
38+
Em aplicativos grandes, talvez seja necessário dividí-lo em partes menores e carregar apenas um componente do servidor quando necessário.. Para tornar isso possível, o Vue tem o método `defineAsyncComponent`:
4939

5040
```js
5141
const app = Vue.createApp({})
@@ -54,17 +44,17 @@ const AsyncComp = Vue.defineAsyncComponent(
5444
() =>
5545
new Promise((resolve, reject) => {
5646
resolve({
57-
template: '<div>I am async!</div>'
47+
template: '<div>Eu sou assíncrono!</div>',
5848
})
5949
})
6050
)
6151

6252
app.component('async-example', AsyncComp)
6353
```
6454

65-
As you can see, this method accepts a factory function returning a `Promise`. Promise's `resolve` callback should be called when you have retrieved your component definition from the server. You can also call `reject(reason)` to indicate the load has failed.
55+
Como você pode ver, esse método aceita uma função de fabricação (_factory function_) que retorna uma `Promise`. O retorno de chamada `resolve` da Promise deve ser chamado quando você recuperar sua definição de componente do servidor. Você também pode chamar `reject(reason)` para indicar que o carregamento falhou.
6656

67-
You can also return a `Promise` in the factory function, so with Webpack 2 or later and ES2015 syntax you can do:
57+
Você também pode retornar uma `Promise` na função de fabricação. Portanto, com a sintaxe do Webpack 2+ ou ES2015, você pode fazer:
6858

6959
```js
7060
import { defineAsyncComponent } from 'vue'
@@ -76,7 +66,7 @@ const AsyncComp = defineAsyncComponent(() =>
7666
app.component('async-component', AsyncComp)
7767
```
7868

79-
You can also use `defineAsyncComponent` when [registering a component locally](component-registration.html#local-registration):
69+
Você também pode usar o `defineAsyncComponent` ao [registrar um componente localmente](component-registration.html#local-registration):
8070

8171
```js
8272
import { createApp, defineAsyncComponent } from 'vue'
@@ -86,15 +76,15 @@ createApp({
8676
components: {
8777
AsyncComponent: defineAsyncComponent(() =>
8878
import('./components/AsyncComponent.vue')
89-
)
90-
}
79+
),
80+
},
9181
})
9282
```
9383

94-
### Using with Suspense
84+
### Usando com Suspense
9585

96-
Async components are _suspensible_ by default. This means if it has a [`<Suspense>`](TODO) in the parent chain, it will be treated as an async dependency of that `<Suspense>`. In this case, the loading state will be controlled by the `<Suspense>`, and the component's own loading, error, delay and timeout options will be ignored.
86+
Os componentes assíncronos são _suspensos_ por padrão. Isso significa que, se houver um [`<Suspense>`](TODO) na cadeia (pai), ele será tratado como uma dependência assíncrona desse `<Suspense>`. Nesse caso, o estado de carregamento vai se controlado pelo `<Suspense>`, e as opções de carregamento, erro, atraso e tempo limite do próprio componente serão ignoradas.
9787

98-
The async component can opt-out of `Suspense` control and let the component always control its own loading state by specifying `suspensible: false` in its options.
88+
O componente assíncrono pode cancelar o controle do `Suspense` e deixar que o componente sempre controle seu próprio estado de carregamento, especificando `suspensible: false` em suas opções.
9989

100-
You can check the list of available options in the [API Reference](../api/global-api.html#arguments-4)
90+
Você pode conferir a lista de opções disponíveis na [Referência da API](../api/global-api.html#arguments-4)

0 commit comments

Comments
 (0)