forked from vuejs/docs
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c027cbc
commit 161ed2f
Showing
8 changed files
with
151 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
# Client Side Hydration | ||
# Hidratação _Client-Side_ | ||
|
||
Hydration refers to the client-side process during which Vue takes over the static HTML sent by the server and turns it into dynamic DOM that can react to client-side data changes. | ||
Hidratação refere-se ao processo _client-side_ durante o qual o Vue assume o HTML estático enviado pelo servidor e o transforma em DOM dinâmico que pode reagir às alterações de dados _client-side_. | ||
|
||
In `entry-client.js`, we are simply mounting the app with this line: | ||
Em `entry-client.js`, estamos simplesmente montando o aplicativo com esta linha: | ||
|
||
```js | ||
app.mount('#app') | ||
``` | ||
|
||
Since the server has already rendered the markup, we obviously do not want to throw that away and re-create all the DOM elements. Instead, we want to "hydrate" the static markup and make it interactive. | ||
Como o servidor já renderizou a marcação, obviamente não queremos jogar isso fora e recriar todos os elementos DOM. Em vez disso, queremos "hidratar" a marcação estática e torná-la interativa. | ||
|
||
Vue provides a `createSSRApp` method for use in client-side code (in this case, in our `entry-client.js`) to tell Vue to hydrate the existing static HTML instead of re-creating all the DOM elements. | ||
O Vue fornece um método `createSSRApp` para uso no código _client-side_ (neste caso, em nosso `entry-client.js`) para dizer ao Vue para hidratar o HTML estático existente em vez de recriar todos os elementos DOM. | ||
|
||
### Hydration Caveats | ||
### Limitações da Hidratação | ||
|
||
Vue will assert the client-side generated virtual DOM tree matches the DOM structure rendered from the server. If there is a mismatch, it will bail hydration, discard existing DOM and render from scratch. There will be a warning in the browser console but your site will still work. | ||
O Vue confirmará que a árvore DOM virtual gerada pelo cliente corresponde à estrutura DOM renderizada a partir do servidor. Se houver uma incompatibilidade, ele deixará a hidratação, descartará o DOM existente e renderizará do zero. Haverá um aviso no console do navegador, mas seu site ainda funcionará. | ||
|
||
The first key way to ensure that SSR is working to ensuring your application state is the same on client and server. Take special care not to depend on APIs specific to the browser (like window width, device capability or localStorage) or server (such as Node built-ins), and take care where the same code will give different results when run in different places (such as when using timezones, timestamps, normalizing URLs or generating random numbers). See [Writing Universal Code](./universal.md) for more details. | ||
A primeira forma importante de garantir que o SSR esteja funcionando é garantir que o estado do aplicativo seja o mesmo no cliente e no servidor. Tome cuidado especial para não depender de APIs específicas do navegador (como largura da janela, capacidade do dispositivo ou localStorage) ou do servidor (como _built-ins_ do Node), e tome cuidado onde o mesmo código dará resultados diferentes quando executado em locais diferentes (como ao usar fusos horários, _timestamps_, normalizar URLs ou gerar números aleatórios). Consulte [Escrevendo Código Universal](./universal.md) para mais detalhes. | ||
|
||
A second key thing to be aware of when using SSR + client hydration is that invalid HTML may be altered by the browser. For example, when you write this in a Vue template: | ||
Uma segunda coisa importante a ser observada ao usar o SSR + hidratação no cliente é que HTML inválido pode ser alterado pelo navegador. Por exemplo, quando você escreve isso em um _template_ Vue: | ||
|
||
```html | ||
<table> | ||
<tr> | ||
<td>hi</td> | ||
<td>oi</td> | ||
</tr> | ||
</table> | ||
``` | ||
|
||
The browser will automatically inject `<tbody>` inside `<table>`, however, the virtual DOM generated by Vue does not contain `<tbody>`, so it will cause a mismatch. To ensure correct matching, make sure to write valid HTML in your templates. | ||
O navegador automaticamente injetará `<tbody>` dentro de `<table>`, entretanto, o DOM virtual gerado pelo Vue não contém `<tbody>`, então causará uma incompatibilidade. Para garantir a correspondência correta, certifique-se de escrever um HTML válido em seus _templates_. | ||
|
||
You might consider using a HTML validator like [the W3C Markup Validation Service](https://validator.w3.org/) or [HTML-validate](https://html-validate.org/) to check your templates in development. | ||
Você pode usar um validador de HTML como [o W3C Markup Validation Service](https://validator.w3.org/) ou [HTML-validate](https://html-validate.org/) para verificar seus _templates_ em desenvolvimento. |
Oops, something went wrong.