Skip to content

Commit 2b808b9

Browse files
committed
JSX Selesai
1 parent 159cf30 commit 2b808b9

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/v2/guide/render-function.md

+38-38
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ render: function (createElement) {
457457

458458
## JSX
459459

460-
If you're writing a lot of `render` functions, it might feel painful to write something like this:
460+
Jika kalian menulis fungsi `render` yang panjang, akan menyusahkan jika kalian harus menulis seperti di bawah:
461461

462462
``` js
463463
createElement(
@@ -472,15 +472,15 @@ createElement(
472472
)
473473
```
474474

475-
Especially when the template version is so simple in comparison:
475+
Terutama jika versi templatnya lebih sederhana:
476476

477477
``` html
478478
<anchored-heading :level="1">
479479
<span>Hello</span> world!
480480
</anchored-heading>
481481
```
482482

483-
That's why there's a [Babel plugin](https://github.com/vuejs/jsx) to use JSX with Vue, getting us back to a syntax that's closer to templates:
483+
Karena itulah ada [plugin Babel](https://github.com/vuejs/jsx) untuk menggunakan JSX dengan Vue, memberikan kita cara penulisan yang sedikit mirip templat:
484484

485485
``` js
486486
import AnchoredHeading from './AnchoredHeading.vue'
@@ -497,61 +497,61 @@ new Vue({
497497
})
498498
```
499499

500-
<p class="tip">Aliasing `createElement` to `h` is a common convention you'll see in the Vue ecosystem and is actually required for JSX. Starting with [version 3.4.0](https://github.com/vuejs/babel-plugin-transform-vue-jsx#h-auto-injection) of the Babel plugin for Vue, we automatically inject `const h = this.$createElement` in any method and getter (not functions or arrow functions), declared in ES2015 syntax that has JSX, so you can drop the `(h)` parameter. With prior versions of the plugin, your app would throw an error if `h` was not available in the scope.</p>
500+
<p class="tip">Menamai `createElement` menjadi `h` adalah aturan umum yang akan kalian sering temukan di ekosistem Vue dan wajib dilakukan untuk menggunakan JSX. Mulai dari plugin Babel untuk Vue [versi 3.4.0](https://github.com/vuejs/babel-plugin-transform-vue-jsx#h-auto-injection), secara otomatis diberikan baris `const h = this.$createElement` di method dan getter apa saja (selama bukan fungsi atau fungsi panah / *arrow function*), yang dideklarasikan di penulisan kode ES20155 yang berisi JSX, sehingga kalian bisa menghapus bagian parameter `(h)`. Di versi sebelumnya, akan terjadi error jika tidak ada `h` yang tersedia di lingkup tersebut.</p>
501501

502-
For more on how JSX maps to JavaScript, see the [usage docs](https://github.com/vuejs/jsx#installation).
502+
Untuk pelajari lebih lanjut tentang JSX, lihat [dokumentasi penggunaannya](https://github.com/vuejs/jsx#installation).
503503

504-
## Functional Components
504+
## Komponen Fungsional
505505

506-
The anchored heading component we created earlier is relatively simple. It doesn't manage any state, watch any state passed to it, and it has no lifecycle methods. Really, it's only a function with some props.
506+
Komponen anchored heading yang kita buat sebelumnya relatif sederhana. Tidak ada state, watcher, dan tidak ada method lifecycle. Hanya sebuah fungsi dengan beberapa props.
507507

508-
In cases like this, we can mark components as `functional`, which means that they're stateless (no [reactive data](../api/#Options-Data)) and instanceless (no `this` context). A **functional component** looks like this:
508+
Dalam kasus ini, kita bisa menandai komponen ini dengan `functional`, artinya mereka tidak memiliki state (tidak ada [reactive data](../api/#Options-Data)) dan tanpa instan (tidak ada konteks `this`). **Komponen fungsional** terlihat seperti ini:
509509

510510
``` js
511511
Vue.component('my-component', {
512512
functional: true,
513-
// Props are optional
513+
// Props bersifat opsional
514514
props: {
515515
// ...
516516
},
517-
// To compensate for the lack of an instance,
518-
// we are now provided a 2nd context argument.
517+
// Karena tidak ada instan,
518+
// konteks diteruskan melalui parameter kedua
519519
render: function (createElement, context) {
520520
// ...
521521
}
522522
})
523523
```
524524

525-
> Note: in versions before 2.3.0, the `props` option is required if you wish to accept props in a functional component. In 2.3.0+ you can omit the `props` option and all attributes found on the component node will be implicitly extracted as props.
525+
> Catatan: di versi sebelum 2.3.0, opsi `props` harus ditulis jika kalian ingin komponen fungsional kalian menerima props. Di versi 2.3.0 ke atas, kalian tidak perlu menulis opsi `props` dan semua atribut yang ada di node komponen tersebut akan secara otomatis diambil sebagai props.
526526
527-
In 2.5.0+, if you are using [single-file components](single-file-components.html), template-based functional components can be declared with:
527+
Di versi 2.5.0 ke atas, jika kalian menggunakan [kopmonen satu berkas / single-file components](single-file-components.html), komponen fungsional yang menggunakan templat bisa ditulis seperti di bawah:
528528

529529
``` html
530530
<template functional>
531531
</template>
532532
```
533533

534-
Everything the component needs is passed through `context`, which is an object containing:
534+
Semua yang dibutuhkan oleh komponen akan diteruskan melalui `context`, sebuah objek yang berisi:
535535

536-
- `props`: An object of the provided props
537-
- `children`: An array of the VNode children
538-
- `slots`: A function returning a slots object
539-
- `scopedSlots`: (2.6.0+) An object that exposes passed-in scoped slots. Also exposes normal slots as functions.
540-
- `data`: The entire [data object](#The-Data-Object-In-Depth), passed to the component as the 2nd argument of `createElement`
541-
- `parent`: A reference to the parent component
542-
- `listeners`: (2.3.0+) An object containing parent-registered event listeners. This is an alias to `data.on`
543-
- `injections`: (2.3.0+) if using the [`inject`](../api/#provide-inject) option, this will contain resolved injections.
536+
- `props`: objek berisi props
537+
- `children`: Array VNode yang berisi anak dari komponen tersebut
538+
- `slots`: Fungsi yang mengembalikan objek slot
539+
- `scopedSlots`: (2.6.0+) Objek yang berisi slot berlingkup. Juga menyediakan slot normal sebagai fungsi.
540+
- `data`: [data objek](#The-Data-Object-In-Depth), diteruskan ke komponen sebagai argumen kedua dari `createElement`
541+
- `parent`: Referensi ke komponen di atasnya
542+
- `listeners`: (2.3.0+) Objek yang berisi event listener yang didaftarkan oleh komponen di atasnya. Juga sebagai alias untuk `data.on`
543+
- `injections`: (2.3.0+) jika ada opsi [`inject`](../api/#provide-inject), akan berisi injeksi yang ditemukan/diresolve.
544544

545-
After adding `functional: true`, updating the render function of our anchored heading component would require adding the `context` argument, updating `this.$slots.default` to `context.children`, then updating `this.level` to `context.props.level`.
545+
Setelah menuliskan `functional: true`, pembaharuan fungsi render dari komponen anchored heading yang baru dibuat mengharuskan kalian menambahkan argumen `context`, merubah `this.$slots.default` menjadi `context.children`, lalu merubah `this.level` menjadi `context.props.level`.
546546

547-
Since functional components are just functions, they're much cheaper to render. However, the lack of a persistent instance means they won't show up in the [Vue devtools](https://github.com/vuejs/vue-devtools) component tree.
547+
Karena komponen fungsional hanya sebuah fungsi saja, mereka lebih cepat untuk dirender. Tetapi, karena tidak adanya instan yang bisa dijadikan acuan, komponen fungsional tidak akan muncul di pohon komponen [Vue devtools](https://github.com/vuejs/vue-devtools).
548548

549-
They're also very useful as wrapper components. For example, when you need to:
549+
Mereka sangat bermanfaat jika digunakan sebagai komponen pembungkus. Contohnya:
550550

551-
- Programmatically choose one of several other components to delegate to
552-
- Manipulate children, props, or data before passing them on to a child component
551+
- Secara program memilih beberapa komponen yang akan didelegasikan
552+
- Memanipulasi isi, props, dan data sebelum meneruskannya ke komponen lain di dalamnya
553553

554-
Here's an example of a `smart-list` component that delegates to more specific components, depending on the props passed to it:
554+
Berikut adalah contoh untuk komponen `smart-list` yang akan mengembalikan komponen yang lebih spesifik, tergantung dari props yang diberikan:
555555

556556
``` js
557557
var EmptyList = { /* ... */ }
@@ -588,25 +588,25 @@ Vue.component('smart-list', {
588588
})
589589
```
590590

591-
### Passing Attributes and Events to Child Elements/Components
591+
### Meneruskan Atribut dan Event ke Anak Komponen
592592

593-
On normal components, attributes not defined as props are automatically added to the root element of the component, replacing or [intelligently merging with](class-and-style.html) any existing attributes of the same name.
593+
Umumnya, atribut yang tidak didefinisikan sebagai prop akan otomatis ditambahkan ke elemen akar dari komponen tersebut, menindih atau [menggabungkan dengan seksama](class-and-style.html) atribut yang sudah ada dengan nama yang sama.
594594

595-
Functional components, however, require you to explicitly define this behavior:
595+
Tetapi untuk komponen fungsional, kalian harus secara tertulis mendefinisikannya:
596596

597597
```js
598598
Vue.component('my-functional-button', {
599599
functional: true,
600600
render: function (createElement, context) {
601-
// Transparently pass any attributes, event listeners, children, etc.
601+
// Teruskan atribut, event listener, anak, dan sebagainya.
602602
return createElement('button', context.data, context.children)
603603
}
604604
})
605605
```
606606

607-
By passing `context.data` as the second argument to `createElement`, we are passing down any attributes or event listeners used on `my-functional-button`. It's so transparent, in fact, that events don't even require the `.native` modifier.
607+
Dengan meneruskan `context.data` sebagai argumen kedua dari `createElement`, kita juga meneruskan atribut dan event lain yang digunakan di `my-functional-button`. Kalian tidak butuh menambahkan modifier `.native`.
608608

609-
If you are using template-based functional components, you will also have to manually add attributes and listeners. Since we have access to the individual context contents, we can use `data.attrs` to pass along any HTML attributes and `listeners` _(the alias for `data.on`)_ to pass along any event listeners.
609+
Jika kalian menggunakan komponen fungsional berbasis templat, kalian harus meneruskan atribut dan listener secara manual. Kalian bisa menggunakan `data.attrs` untuk meneruskan atribut HTML, dan `listeners` _(alias dari `data.on`)_ untuk meneruskan event listener.
610610

611611
```html
612612
<template functional>
@@ -622,7 +622,7 @@ If you are using template-based functional components, you will also have to man
622622

623623
### `slots()` vs `children`
624624

625-
You may wonder why we need both `slots()` and `children`. Wouldn't `slots().default` be the same as `children`? In some cases, yes - but what if you have a functional component with the following children?
625+
Jika kalian penasaran kenapa kita butuh `slots()` dan `children`. Dan bukankah `slots().default` sama dengan `children`? Di beberapa kasus, iya - tapi bagaimana jika kita punya komponen fungsional seperti di bawah?
626626

627627
``` html
628628
<my-functional-component>
@@ -633,11 +633,11 @@ You may wonder why we need both `slots()` and `children`. Wouldn't `slots().defa
633633
</my-functional-component>
634634
```
635635

636-
For this component, `children` will give you both paragraphs, `slots().default` will give you only the second, and `slots().foo` will give you only the first. Having both `children` and `slots()` therefore allows you to choose whether this component knows about a slot system or perhaps delegates that responsibility to another component by passing along `children`.
636+
Untuk komponen ini, `children` akan mengembalikan kedua paragraf; sedangkan `slots().default` akan mengembalikan yang kedua saja, dan `slots().foo` akan mengembalikan yang pertama saja. Adanya `children` dan `slots()` memberi keluasan untuk memilih apakah komponen yang kita buat tahu tentang slot yang kita gunakan, atau mungkin hanya ingin meneruskan masalah pemilihan slot tersebut ke komponen lain sembari juga meneruskan `children`.
637637

638-
## Template Compilation
638+
## Kompilasi Templat
639639

640-
You may be interested to know that Vue's templates actually compile to render functions. This is an implementation detail you usually don't need to know about, but if you'd like to see how specific template features are compiled, you may find it interesting. Below is a little demo using `Vue.compile` to live-compile a template string:
640+
Kalian mungkin penasaran, bagaimana caranya templat Vue bisa dirubah menjadi fungsi render. Detail implementasi ini tidak wajib untuk diketahui. Tapi jika kalian penasaran, di bawah ini adalah demo menggunakan `Vue.compile` untuk secara langsung merubah string templat menjadi fungsi render:
641641

642642
{% raw %}
643643
<div id="vue-compile-demo" class="demo">

0 commit comments

Comments
 (0)