|
1 |
| -# Single File Components |
| 1 | +# Componentes Single-File |
2 | 2 |
|
3 |
| -## Introduction |
| 3 | +## Introdução |
4 | 4 |
|
5 |
| -In many Vue projects, global components will be defined using `app.component()`, followed by `app.mount('#app')` to target a container element in the body of every page. |
| 5 | +Em muitos projetos Vue, os componentes globais serão definidos usando `app.component()`, seguido por `app.mount('#app')` mirando em um elemento contêiner no corpo de cada página. |
6 | 6 |
|
7 |
| -This can work very well for small to medium-sized projects, where JavaScript is only used to enhance certain views. In more complex projects however, or when your frontend is entirely driven by JavaScript, these disadvantages become apparent: |
| 7 | +Isto pode funcionar bem em projetos pequenos e médios, onde o JavaScript só é utilizado para incrementar certas interfaces. No entanto, em projetos mais complexos ou quando o _frontend_ é totalmente orientado pelo JavaScript, tais desvantagens se tornam aparentes: |
8 | 8 |
|
9 |
| -- **Global definitions** force unique names for every component |
10 |
| -- **String templates** lack syntax highlighting and require ugly slashes for multiline HTML |
11 |
| -- **No CSS support** means that while HTML and JavaScript are modularized into components, CSS is conspicuously left out |
12 |
| -- **No build step** restricts us to HTML and ES5 JavaScript, rather than preprocessors like Pug (formerly Jade) and Babel |
| 9 | +- **Definições globais** forçam nomes únicos para cada componente |
| 10 | +- **Templates com Strings** não têm realce de sintaxe e são difíceis de ler em múltiplas linhas |
| 11 | +- **Sem suporte ao CSS** enquanto HTML e JavaScript são modularizados em componentes, CSS é notavelmente deixado de fora |
| 12 | +- **Sem processamento no build** ou seja, nos restringindo a HTML e JavaScript ES5, em vez de pré-processadores como Pug (anteriormente Jade) e Babel |
13 | 13 |
|
14 |
| -All of these are solved by **single-file components** with a `.vue` extension, made possible with build tools such as Webpack or Browserify. |
| 14 | +Tudo isso é resolvido através dos **Componentes Single-File** com a extensão `.vue`, possibilitados graças a ferramentas de _build_ como Webpack ou Browserify. |
15 | 15 |
|
16 |
| -Here's an example of a file we'll call `Hello.vue`: |
| 16 | +Aqui está um exemplo de um arquivo que chamaremos de `Hello.vue`: |
17 | 17 |
|
18 |
| -<a href="https://codepen.io/team/Vue/pen/3de13b5cd0133df4ecf307b6cf2c5f94" target="_blank" rel="noopener noreferrer"><img src="/images/sfc.png" width="403" alt="Single-file component example (click for code as text)" style="display: block; margin: 15px auto; max-width: 100%"></a> |
| 18 | +<a href="https://codepen.io/team/Vue/pen/3de13b5cd0133df4ecf307b6cf2c5f94" target="_blank" rel="noopener noreferrer"><img src="/images/sfc.png" width="403" alt="Exemplo de componente single-file (clique para ver o código em texto)" style="display: block; margin: 15px auto; max-width: 100%"></a> |
19 | 19 |
|
20 |
| -Now we get: |
| 20 | +Agora nós obtivemos: |
21 | 21 |
|
22 |
| -- [Complete syntax highlighting](https://github.com/vuejs/awesome-vue#source-code-editing) |
23 |
| -- [CommonJS modules](https://webpack.js.org/concepts/modules/#what-is-a-webpack-module) |
24 |
| -- [Component-scoped CSS](https://vue-loader.vuejs.org/en/features/scoped-css.html) |
| 22 | +- [Realce de sintaxe completo](https://github.com/vuejs/awesome-vue#source-code-editing) |
| 23 | +- [Módulos tipo CommonJS](https://webpack.js.org/concepts/modules/#what-is-a-webpack-module) |
| 24 | +- [Escopo de CSS por componente](https://vue-loader.vuejs.org/en/features/scoped-css.html) |
25 | 25 |
|
26 |
| -As promised, we can also use preprocessors such as Pug, Babel (with ES2015 modules), and Stylus for cleaner and more feature-rich components. |
| 26 | +Como prometido, também podemos utilizar pré-processadores como Pug (Jade), Babel (com módulos ES2015+) e Stylus para componentes mais limpos e mais ricos em recursos. |
27 | 27 |
|
28 |
| -<a href="https://codesandbox.io/s/vue-single-file-component-with-pre-processors-mr3ik?file=/src/App.vue" target="_blank" rel="noopener noreferrer"><img src="/images/sfc-with-preprocessors.png" width="563" alt="Single-file component with pre-processors example (click for code as text)" style="display: block; margin: 15px auto; max-width: 100%"></a> |
| 28 | +<a href="https://codesandbox.io/s/vue-single-file-component-with-pre-processors-mr3ik?file=/src/App.vue" target="_blank" rel="noopener noreferrer"><img src="/images/sfc-with-preprocessors.png" width="563" alt="Exemplo de componente single-file com pré-processadores (clique para ver o código em texto)" style="display: block; margin: 15px auto; max-width: 100%"></a> |
29 | 29 |
|
30 |
| -These specific languages are only examples. You could as easily use TypeScript, SCSS, PostCSS, or whatever other preprocessors that help you be productive. If using Webpack with `vue-loader`, it also has first-class support for CSS Modules. |
| 30 | +Estas linguagens específicas são meros exemplos. Poderíamos tão facilmente usar TypeScript, SCSS, PostCSS - ou qualquer outro que acreditarmos nos tornar mais produtivos. Se usar Webpack com `vue-loader`, também há suporte de primeira classe a CSS Modules. |
31 | 31 |
|
32 |
| -### What About Separation of Concerns? |
| 32 | +### E a Separação de Responsabilidades? |
33 | 33 |
|
34 |
| -One important thing to note is that **separation of concerns is not equal to separation of file types.** In modern UI development, we have found that instead of dividing the codebase into three huge layers that interweave with one another, it makes much more sense to divide them into loosely-coupled components and compose them. Inside a component, its template, logic and styles are inherently coupled, and collocating them actually makes the component more cohesive and maintainable. |
| 34 | +Uma coisa importante a observar é que **separação de responsabilidades não é igual a separação de tipos de arquivo**. No desenvolvimento moderno de interfaces, chegamos à conclusão de que, ao invés de dividir a base de código em três grandes camadas que se entrelaçam umas com as outras, faz muito mais sentido dividi-las em componentes fracamente acoplados e utilizá-los para composição. Dentro de um componente, seu template, sua lógica e seus estilos são inerentemente acoplados, e encará-los dessa forma os torna componentes mais coesos e manuteníveis. |
35 | 35 |
|
36 |
| -Even if you don't like the idea of Single-File Components, you can still leverage its hot-reloading and pre-compilation features by separating your JavaScript and CSS into separate files: |
| 36 | +Se mesmo assim não gostar da ideia de Componentes _Single-File_, você ainda pode tirar vantagem de seus recursos de _hot-reloading_ (recompilação e atualização em tempo real ao salvar o código) e de pré-compilação, separando JavaScript e CSS em arquivos distintos: |
37 | 37 |
|
38 | 38 | ```html
|
39 | 39 | <!-- my-component.vue -->
|
40 | 40 | <template>
|
41 |
| - <div>This will be pre-compiled</div> |
| 41 | + <div>Isso será pré-compilado</div> |
42 | 42 | </template>
|
43 | 43 | <script src="./my-component.js"></script>
|
44 | 44 | <style src="./my-component.css"></style>
|
45 | 45 | ```
|
46 | 46 |
|
47 |
| -## Getting Started |
| 47 | +## Primeiros Passos |
48 | 48 |
|
49 |
| -### Example Sandbox |
| 49 | +### Sandbox de Exemplo |
50 | 50 |
|
51 |
| -If you want to dive right in and start playing with single-file components, check out [this simple todo app](https://codesandbox.io/s/vue-todo-list-app-with-single-file-component-vzkl3?file=/src/App.vue) on CodeSandbox. |
| 51 | +Se você quiser se mergulhar agora mesmo e começar a brincar com Componentes _Single-File_, dê uma olhada [neste aplicativo de lista de tarefas simples](https://codesandbox.io/s/vue-todo-list-app-with-single-file-component-vzkl3?file=/src/App.vue) no CodeSandbox. |
52 | 52 |
|
53 |
| -### For Users New to Module Build Systems in JavaScript |
| 53 | +### Para Iniciantes em Empacotadores JS |
54 | 54 |
|
55 |
| -With `.vue` components, we're entering the realm of advanced JavaScript applications. That means learning to use a few additional tools if you haven't already: |
| 55 | +Com componentes `.vue`, estamos entrando no reino das aplicações JavaScript avançadas. Significa aprender a utilizar algumas ferramentas adicionais se ainda não teve oportunidade: |
56 | 56 |
|
57 |
| -- **Node Package Manager (npm)**: Read the [Getting Started guide](https://docs.npmjs.com/packages-and-modules/getting-packages-from-the-registry) section about how to get packages from the registry. |
| 57 | +- **Node Package Manager (npm)**: Leia o guia de [Primeiros Passos](https://docs.npmjs.com/packages-and-modules/getting-packages-from-the-registry) do NPM na seção sobre como obter pacotes do registro. |
58 | 58 |
|
59 |
| -- **Modern JavaScript with ES2015/16**: Read through Babel's [Learn ES2015 guide](https://babeljs.io/docs/en/learn). You don't have to memorize every feature right now, but keep this page as a reference you can come back to. |
| 59 | +- **JavaScript Moderno com ES2015/16**: Leia o guia [Aprendendo ES2015](https://babeljs.io/docs/en/learn) do Babel. Não é necessário memorizar cada recurso agora, mas mantenha esta página como referência. |
60 | 60 |
|
61 |
| -After you've taken a day to dive into these resources, we recommend checking out [Vue CLI](https://cli.vuejs.org/). Follow the instructions and you should have a Vue project with `.vue` components, ES2015, webpack and hot-reloading in no time! |
| 61 | +Depois que tiver tirado um dia para mergulhar nestes tópicos, recomendamos dar uma olhada no [Vue CLI](https://cli.vuejs.org/). Seguindo as instruções, você terá em mãos um projeto Vue com componentes `.vue`, ES2015, Webpack e _hot-reloading_, rodando em pouquíssimo tempo! |
62 | 62 |
|
63 |
| -### For Advanced Users |
| 63 | +### Para Usuários Avançados |
64 | 64 |
|
65 |
| -The CLI takes care of most of the tooling configurations for you, but also allows fine-grained customization through its own [config options](https://cli.vuejs.org/config/). |
| 65 | +A CLI cuida da maioria das configurações de ferramentas para você, mas também permite a personalização refinada através de suas próprias [opções de configuração](https://cli.vuejs.org/config/). |
66 | 66 |
|
67 |
| -In case you prefer setting up your own build setup from scratch, you will need to manually configure webpack with [vue-loader](https://vue-loader.vuejs.org). To learn more about webpack itself, check out [their official docs](https://webpack.js.org/configuration/) and [webpack learning academy](https://webpack.academy/p/the-core-concepts). |
| 67 | +Caso você prefira configurar seu próprio _build_ a partir do zero, você precisará configurar manualmente o Webpack com o [vue-loader](https://vue-loader.vuejs.org). Para saber mais sobre o Webpack, confira os [documentos oficiais](https://webpack.js.org/configuration/) e a [Webpack Academy](https://webpack.academy/p/the-core-concepts). |
0 commit comments