You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/component-registration.md
+37-37Lines changed: 37 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
# Component Registration
1
+
# Registro de Componentes
2
2
3
-
> This page assumes you've already read the [Components Basics](component-basics.md). Read that first if you are new to components.
3
+
> Esta página assume que você já leu o [Básico sobre Componentes](component-basics.md). Leia ela primeiro se você for novo no assunto de componentização.
4
4
5
-
## Component Names
5
+
## Nomes de Componentes
6
6
7
-
When registering a component, it will always be given a name. For example, in the global registration we've seen so far:
7
+
Ao registrar um componente, ele sempre receberá um nome. Por exemplo, no registro global que vimos até agora:
The component's name is the first argument of `app.component`. In the example above, the component's name is "my-component-name".
17
+
O nome do componente é o primeiro argumento de `app.component`. No exemplo acima, o nome do componente é "my-component-name".
18
18
19
-
The name you give a component may depend on where you intend to use it. When using a component directly in the DOM (as opposed to in a string template or [single-file component](../guide/single-file-component.html)), we strongly recommend following the [W3C rules](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name)for custom tag names:
19
+
O nome que você dá a um componente pode depender de onde você pretende usá-lo. Ao usar um componente diretamente no DOM (ao contrário de um template string ou [componente de arquivo único](../guide/single-file-component.html)), recomendamos seguir as [regras do W3C](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name)para nomes de tags personalizadas:
20
20
21
-
1.All lowercase
22
-
2.Contains a hyphen (i.e., has multiple words connected with the hyphen symbol)
21
+
1.Todas as letras minúsculas; e
22
+
2.Contém hífen (ou seja, tem várias palavras conectadas com o símbolo de hífen).
23
23
24
-
By doing so, this will help you avoid conflicts with current and future HTML elements.
24
+
Ao nomear dessa maneira, isso o ajudará a evitar conflitos com elementos HTML atuais e futuros.
25
25
26
-
You can see other recommendations for component names in the [Style Guide](../style-guide/#base-component-names-strongly-recommended).
26
+
Você pode ver outras recomendações para nomes de componentes no [Guia de Estilo](../style-guide/#base-component-names-strongly-recommended).
27
27
28
-
### Name Casing
28
+
### Nomeação
29
29
30
-
When defining components in a string template or a single-file component, you have two options when defining component names:
30
+
Ao definir componentes em um template string ou um componente de arquivo único, você tem duas opções ao definir os nomes dos componentes:
31
31
32
-
#### With kebab-case
32
+
#### Com kebab-case
33
33
34
34
```js
35
35
app.component('my-component-name', {
36
36
/* ... */
37
37
})
38
38
```
39
39
40
-
When defining a component with kebab-case, you must also use kebab-case when referencing its custom element, such as in`<my-component-name>`.
40
+
Ao definir um componente com kebab-case, você também deve usar kebab-case ao fazer referência a seu elemento personalizado, como em`<my-component-name>`.
41
41
42
-
#### With PascalCase
42
+
#### Com PascalCase
43
43
44
44
```js
45
45
app.component('MyComponentName', {
46
46
/* ... */
47
47
})
48
48
```
49
49
50
-
When defining a component with PascalCase, you can use either case when referencing its custom element. That means both`<my-component-name>`and`<MyComponentName>`are acceptable. Note, however, that only kebab-case names are valid directly in the DOM (i.e. non-string templates).
50
+
Ao definir um componente com PascalCase, você pode usar qualquer um dos casos ao fazer referência a seu elemento personalizado. Isso significa que`<my-component-name>`e`<MyComponent-name>`são aceitáveis. Observe, no entanto, que apenas os nomes kebab-case são válidos diretamente no DOM (ou seja, templates não-string).
51
51
52
-
## Global Registration
52
+
## Registro Global
53
53
54
-
So far, we've only created components using`app.component`:
54
+
Até agora, só criamos componentes usando`app.component`:
These components are**globally registered**for the application. That means they can be used in the template of any component instance within this application:
62
+
Esses componentes são**globalmente registrados**para a aplicação. Isso significa que eles podem ser usados no template de qualquer instância de componente nesta aplicação:
63
63
64
64
```js
65
65
constapp=Vue.createApp({})
@@ -85,13 +85,13 @@ app.mount('#app')
85
85
</div>
86
86
```
87
87
88
-
This even applies to all subcomponents, meaning all three of these components will also be available _inside each other_.
88
+
Isso se aplica até mesmo a todos os subcomponentes, o que significa que estes três componentes também estarão disponíveis _dentro uns dos outros_.
89
89
90
-
## Local Registration
90
+
## Registro Local
91
91
92
-
Global registration often isn't ideal. For example, if you're using a build system like Webpack, globally registering all components means that even if you stop using a component, it could still be included in your final build. This unnecessarily increases the amount of JavaScript your users have to download.
92
+
O registro global geralmente não é o ideal. Por exemplo, se você estiver usando um sistema de empacotador de módulos como o Webpack, registrar globalmente todos os componentes significa que, mesmo se você parar de usar um componente, ele ainda poderá ser incluído em seu executável final. Isso aumenta desnecessariamente a quantidade de código JavaScript que seus usuários precisam fazer download.
93
93
94
-
In these cases, you can define your components as plain JavaScript objects:
94
+
Nesses casos, você pode definir seus componentes como objetos JavaScript simples:
95
95
96
96
```js
97
97
constComponentA= {
@@ -105,7 +105,7 @@ const ComponentC = {
105
105
}
106
106
```
107
107
108
-
Then define the components you'd like to use in a `components` option:
108
+
Em seguida, defina os componentes que deseja usar na opção de `components`:
109
109
110
110
```js
111
111
constapp=Vue.createApp({
@@ -116,9 +116,9 @@ const app = Vue.createApp({
116
116
})
117
117
```
118
118
119
-
For each property in the`components` object, the key will be the name of the custom element, while the value will contain the options object for the component.
119
+
Para cada propriedade no objeto`components`, a chave será o nome do elemento personalizado, enquanto o valor conterá o objeto de opções para o componente.
120
120
121
-
Note that**locally registered components are _not_ also available in subcomponents**. For example, if you wanted `ComponentA`to be available in `ComponentB`, you'd have to use:
121
+
Observe que**componentes registrados localmente _não_ estão disponíveis em subcomponentes**. Por exemplo, se você quiser que `ComponentA`esteja disponível em `ComponentB`, você terá que usar:
122
122
123
123
```js
124
124
constComponentA= {
@@ -133,7 +133,7 @@ const ComponentB = {
133
133
}
134
134
```
135
135
136
-
Or if you're using ES2015 modules, such as through Babel and Webpack, that might look more like:
136
+
Ou se você estiver usando módulos ES2015, como por meio de Babel e Webpack, isso pode se parecer mais com:
137
137
138
138
```js
139
139
importComponentAfrom'./ComponentA.vue'
@@ -146,20 +146,20 @@ export default {
146
146
}
147
147
```
148
148
149
-
Note that in ES2015+, placing a variable name like `ComponentA`inside an object is shorthand for `ComponentA: ComponentA`, meaning the name of the variable is both:
149
+
Observe que em ES2015+, colocar um nome de variável como `ComponentA`dentro de um objeto é uma abreviação de `ComponentA: ComponentA`, o que significa que o nome da variável é tanto:
150
150
151
-
-the custom element name to use in the template, and
152
-
-the name of the variable containing the component options
151
+
-o nome do elemento personalizado para usar no modelo, quanto
152
+
-o nome da variável que contém as opções do componente.
153
153
154
-
## Module Systems
154
+
## Sistemas de Módulo
155
155
156
-
If you're not using a module system with `import`/`require`, you can probably skip this section for now. If you are, we have some special instructions and tips just for you.
156
+
Se você não estiver usando um sistema de módulo com `import`/`require`, você provavelmente pode pular esta seção por enquanto. Se estiver, temos algumas instruções e dicas especiais para você.
157
157
158
-
### Local Registration in a Module System
158
+
### Registro Local em um Sistema de Módulo
159
159
160
-
If you're still here, then it's likely you're using a module system, such as with Babel and Webpack. In these cases, we recommend creating a `components` directory, with each component in its own file.
160
+
Se você ainda está aqui, é provável que esteja usando um sistema de módulo, como o Babel e o Webpack. Nestes casos, recomendamos a criação de um diretório `components`, com cada componente em seu próprio arquivo.
161
161
162
-
Then you'll need to import each component you'd like to use, before you locally register it. For example, in a hypothetical `ComponentB.js`or`ComponentB.vue` file:
162
+
Em seguida, você precisará importar cada componente que deseja usar, antes de registrá-lo localmente. Por exemplo, em um hipotético arquivo `ComponentB.js`ou`ComponentB.vue`:
163
163
164
164
```js
165
165
importComponentAfrom'./ComponentA'
@@ -174,4 +174,4 @@ export default {
174
174
}
175
175
```
176
176
177
-
Now both`ComponentA`and`ComponentC`can be used inside `ComponentB`'s template.
177
+
Agora, tanto`ComponentA`quanto`ComponentC`podem ser usados dentro do template de `ComponentB`.
0 commit comments