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/render-function.md
+49-49
Original file line number
Diff line number
Diff line change
@@ -246,17 +246,17 @@ render() {
246
246
}
247
247
```
248
248
249
-
## Creating Component VNodes
249
+
## Criando VNodes de Componentes
250
250
251
-
To create a VNode for a component, the first argument passed to`h`should be the component itself:
251
+
Para criar um VNode para um componente, o primeiro argumento passado para`h`deve ser o próprio componente:
252
252
253
253
```js
254
254
render() {
255
255
returnh(ButtonCounter)
256
256
}
257
257
```
258
258
259
-
If we need to resolve a component by name then we can call`resolveComponent`:
259
+
Se precisarmos resolver um componente pelo nome, podemos chamar`resolveComponent`:
260
260
261
261
```js
262
262
const { h, resolveComponent } = Vue
@@ -269,12 +269,12 @@ render() {
269
269
}
270
270
```
271
271
272
-
`resolveComponent`is the same function that templates use internally to resolve components by name.
272
+
`resolveComponent`é a mesma função que os _templates_ usam internamente para resolver componentes por nome.
273
273
274
-
A `render`function will normally only need to use `resolveComponent`for components that are [registered globally](/guide/component-registration.html#global-registration). [Local component registration](/guide/component-registration.html#local-registration) can usually be skipped altogether. Consider the following example:
274
+
Uma função `render`normalmente só precisa usar `resolveComponent`para componentes que são [registrados globalmente](/guide/component-registration.html#registro-global). Assim o [registro local de componentes](/guide/component-registration.html#registro-local) geralmente pode ser ignorado por completo. Considere o seguinte exemplo:
275
275
276
276
```js
277
-
//We can simplify this
277
+
//Podemos simplificar isso
278
278
components: {
279
279
ButtonCounter
280
280
},
@@ -283,7 +283,7 @@ render() {
283
283
}
284
284
```
285
285
286
-
Rather than registering a component by name and then looking it up we can use it directly instead:
286
+
Em vez de registrar um componente pelo nome e depois procurá-lo, podemos usá-lo diretamente:
287
287
288
288
```js
289
289
render() {
@@ -319,7 +319,7 @@ render() {
319
319
}
320
320
```
321
321
322
-
In a template it can be useful to use a `<template>`tag to hold a`v-if`or`v-for` directive. When migrating to a `render` function, the `<template>`tag is no longer required and can be discarded.
322
+
Em um _template_ pode ser útil usar uma tag `<template>`para conter uma diretiva`v-if`ou`v-for`. Ao migrar para uma função `render`, a tag `<template>`não é mais necessária e pode ser descartada.
323
323
324
324
### `v-model`
325
325
@@ -437,23 +437,23 @@ render() {
437
437
}
438
438
```
439
439
440
-
The slots are passed as functions, allowing the child component to control the creation of each slot's contents. Any reactive data should be accessed within the slot function to ensure that it's registered as a dependency of the child component and not the parent. Conversely, calls to`resolveComponent`should be made outside the slot function, otherwise they'll resolve relative to the wrong component:
440
+
Os slots são passados como funções, permitindo que o componente filho controle a criação do conteúdo de cada slot. Quaisquer dados reativos devem ser acessados dentro da função do slot para garantir que sejam registrados como uma dependência do componente filho e não do pai. Por outro lado, chamadas ao`resolveComponent`devem ser feitas fora da função do slot, caso contrário, elas serão resolvidas em relação ao componente errado:
441
441
442
442
```js
443
443
// `<MyButton><MyIcon :name="icon" />{{ text }}</MyButton>`
444
444
render() {
445
-
//Calls to resolveComponent should be outside the slot function
445
+
//Chamadas para resolveComponent devem estar fora da função slot
446
446
constButton=resolveComponent('MyButton')
447
447
constIcon=resolveComponent('MyIcon')
448
448
449
449
returnh(
450
450
Button,
451
451
null,
452
452
{
453
-
// Use an arrow function to preserve the `this` value
453
+
// Use uma arrow function para preservar o valor de `this`
454
454
default: (props) => {
455
-
//Reactive properties should be read inside the slot function
456
-
//so that they become dependencies of the child's rendering
455
+
//Propriedades reativas devem ser lidas dentro da função slot
456
+
//para que se tornem dependências da renderização do filho
457
457
return [
458
458
h(Icon, { name:this.icon }),
459
459
this.text
@@ -464,40 +464,40 @@ render() {
464
464
}
465
465
```
466
466
467
-
If a component receives slots from its parent, they can be passed on directly to a child component:
467
+
Se um componente recebe slots de seu pai, eles podem ser passados diretamente para um componente filho:
468
468
469
469
```js
470
470
render() {
471
471
returnh(Panel, null, this.$slots)
472
472
}
473
473
```
474
474
475
-
They can also be passed individually or wrapped as appropriate:
475
+
Eles também podem ser passados individualmente ou envolvidos conforme apropriado:
Behind the scenes, templates use `resolveDynamicComponent`to implement the `is` attribute. We can use the same function if we need all the flexibility provided by `is`in our `render` function:
500
+
Nos bastidores, os _templates_ usam `resolveDynamicComponent`para implementar o atributo `is`. Podemos usar a mesma função se precisarmos de toda a flexibilidade fornecida por `is`em nossa função `render`:
501
501
502
502
```js
503
503
const { h, resolveDynamicComponent } = Vue
@@ -511,13 +511,13 @@ render() {
511
511
}
512
512
```
513
513
514
-
Just like`is`, `resolveDynamicComponent`supports passing a component name, an HTML element name, or a component options object.
514
+
Assim como`is`, `resolveDynamicComponent`suporta a passagem de um nome de componente, um nome de elemento HTML ou um objeto de opções de componente.
515
515
516
-
However, that level of flexibility is usually not required. It's often possible to replace`resolveDynamicComponent`with a more direct alternative.
516
+
No entanto, esse nível de flexibilidade geralmente não é necessário. Muitas vezes é possível substituir`resolveDynamicComponent`por uma alternativa mais direta.
517
517
518
-
For example, if we only need to support component names then `resolveComponent`can be used instead.
518
+
Por exemplo, se precisarmos apenas oferecer suporte a nomes de componentes, então `resolveComponent`pode ser usado.
519
519
520
-
If the VNode is always an HTML element then we can pass its name directly to`h`:
520
+
Se o VNode for sempre um elemento HTML, podemos passar seu nome diretamente para`h`:
Similarly, if the value passed to`is`is a component options object then there's no need to resolve anything, it can be passed directly as the first argument of`h`.
529
+
Da mesma forma, se o valor passado para`is`for um objeto de opções de componente, então não há necessidade de resolver nada, ele pode ser passado diretamente como o primeiro argumento de`h`.
530
530
531
-
Much like a `<template>` tag, a `<component>`tag is only required in templates as a syntactical placeholder and should be discarded when migrating to a `render` function.
531
+
Assim como uma tag `<template>`, uma tag `<component>`só é necessária em _templates_ como um espaço reservado sintático e deve ser descartada ao migrar para uma função `render`.
532
532
533
-
### Custom Directives
533
+
### Diretivas Personalizadas
534
534
535
-
Custom directives can be applied to a VNode using[`withDirectives`](/api/global-api.html#withdirectives):
535
+
Diretivas personalizadas podem ser aplicadas a um VNode usando[`withDirectives`](/api/global-api.html#withdirectives):
[`resolveDirective`](/api/global-api.html#resolvedirective)is the same function that templates use internally to resolve directives by name. That is only necessary if you don't already have direct access to the directive's definition object.
552
+
[`resolveDirective`](/api/global-api.html#resolvedirective)é a mesma função que os _templates_ usam internamente para resolver diretivas por nome. Isso só é necessário se você ainda não tiver acesso direto ao objeto de definição da diretiva.
553
553
554
-
### Built-in Components
554
+
### Componentes Integrados
555
555
556
-
[Built-in components](/api/built-in-components.html) such as `<keep-alive>`, `<transition>`, `<transition-group>`, and`<teleport>`are not registered globally by default. This allows bundlers to perform tree-shaking, so that the components are only included in the build if they are used. However, that also means we can't access them using`resolveComponent`or`resolveDynamicComponent`.
556
+
[Componentes integrados](/api/built-in-components.html), como `<keep-alive>`, `<transition>`, `<transition-group>` e`<teleport>`por padrão não são registrados globalmente. Isso permite que empacotadores executem o _tree-shaking_ para que os componentes sejam incluídos na compilação apenas se forem usados. No entanto, isso também significa que não podemos acessá-los usando`resolveComponent`ou`resolveDynamicComponent`.
557
557
558
-
Templates have special handling for those components, automatically importing them when they are used. When we're writing our own `render` functions, we need to import them ourselves:
558
+
_Templates_ possuem tratamento especial para esses componentes, importando-os automaticamente quando utilizados. Quando estamos escrevendo nossas próprias funções `render`, precisamos importá-las nós mesmos:
## Valores de Retorno para Funções de Renderização
571
571
572
-
In all of the examples we've seen so far, the `render`function has returned a single root VNode. However, there are alternatives.
572
+
Em todos os exemplos que vimos até agora, a função `render`retornou um único VNode raiz. No entanto, existem alternativas.
573
573
574
-
Returning a string will create a text VNode, without any wrapping element:
574
+
Retornar uma string criará um VNode de texto, sem nenhum elemento de encapsulamento:
575
575
576
576
```js
577
577
render() {
578
-
return'Hello world!'
578
+
return'Olá mundo!'
579
579
}
580
580
```
581
581
582
-
We can also return an array of children, without wrapping them in a root node. This creates a fragment:
582
+
Também podemos retornar um array de filhos, sem envolvê-los em um nó raiz. Isso cria um fragmento:
583
583
584
584
```js
585
-
//Equivalent to a template of `Hello<br>world!`
585
+
//Equivalente a um template de `Olá<br>mundo!`
586
586
render() {
587
587
return [
588
-
'Hello',
588
+
'Olá',
589
589
h('br'),
590
-
'world!'
590
+
'mundo!'
591
591
]
592
592
}
593
593
```
594
594
595
-
If a component needs to render nothing, perhaps because data is still loading, it can just return`null`. This will be rendered as a comment node in the DOM.
595
+
Se um componente não precisar renderizar nada, talvez porque os dados ainda estão sendo carregados, ele pode simplesmente retornar`null`. Isso será renderizado como um nó de comentário no DOM.
596
596
597
597
## JSX
598
598
@@ -636,30 +636,30 @@ app.mount('#demo')
636
636
637
637
Para saber mais sobre como JSX mapeia para o JavaScript, veja a [documentação de uso](https://github.com/vuejs/jsx-next#installation).
638
638
639
-
## Functional Components
639
+
## Componentes Funcionais
640
640
641
-
Functional components are an alternative form of component that don't have any state of their own. They are rendered without creating a component instance, bypassing the usual component lifecycle.
641
+
Componentes funcionais são uma forma alternativa de componente que não possui nenhum estado próprio. Eles são renderizados sem criar uma instância de componente, ignorando o ciclo de vida normal do componente.
642
642
643
-
To create a functional component we use a plain function, rather than an options object. The function is effectively the `render`function for the component. As there is no `this`reference for a functional component, Vue will pass in the `props`as the first argument:
643
+
Para criar um componente funcional, usamos uma função simples, em vez de um objeto de opções. A função é efetivamente a função `render`para o componente. Como não há referência de `this`para um componente funcional, o Vue passará o `props`como primeiro argumento:
644
644
645
645
```js
646
646
constFunctionalComponent= (props, context) => {
647
647
// ...
648
648
}
649
649
```
650
650
651
-
The second argument, `context`, contains three properties: `attrs`, `emit`, and`slots`. These are equivalent to the instance properties[`$attrs`](/api/instance-properties.html#attrs), [`$emit`](/api/instance-methods.html#emit), and[`$slots`](/api/instance-properties.html#slots)respectively.
651
+
O segundo argumento, `context`, contém três propriedades: `attrs`, `emit` e`slots`. Elas são equivalentes às propriedades de instância[`$attrs`](/api/instance-properties.html#attrs), [`$emit`](/api/instance-methods.html#emit) e[`$slots`](/api/instance-properties.html#slots)respectivamente.
652
652
653
-
Most of the usual configuration options for components are not available for functional components. However, it is possible to define [`props`](/api/options-data.html#props)and[`emits`](/api/options-data.html#emits)by adding them as properties:
653
+
A maioria das opções de configuração usuais para componentes não está disponível para componentes funcionais. No entanto, é possível definir [`props`](/api/options-data.html#props)e[`emits`](/api/options-data.html#emits)adicionando-os como propriedades:
654
654
655
655
```js
656
656
FunctionalComponent.props= ['value']
657
657
FunctionalComponent.emits= ['click']
658
658
```
659
659
660
-
If the `props`option is not specified, then the `props`object passed to the function will contain all attributes, the same as`attrs`. The prop names will not be normalized to camelCase unless the `props`option is specified.
660
+
Se a opção `props`não for especificada, então o objeto `props`passado para a função conterá todos os atributos, o mesmo que`attrs`. Os nomes das props não serão normalizados para camelCase a menos que a opção `props`seja especificada.
661
661
662
-
Functional components can be registered and consumed just like normal components. If you pass a function as the first argument to `h`, it will be treated as a functional component.
662
+
Componentes funcionais podem ser registrados e consumidos como componentes normais. Se você passar uma função como primeiro argumento para `h`, ela será tratada como um componente funcional.
0 commit comments