Skip to content

Commit 9a80b6d

Browse files
authored
Merge pull request #187 from ikrydev/JSX
JSX Selesai #DevCJogja25
2 parents 159cf30 + fd94e17 commit 9a80b6d

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

src/v2/guide/render-function.md

+53-53
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ order: 303
66

77
## Basics
88

9-
Pada banyak kasus, Vue menganjurkan penggunaan templat untuk membuat HTML. Tetapi, ada beberapa situasi di mana anda butuh menggunakan Javascript secara penuh. Kalian bisa menggunakan **fungsi render**, sebagai alternatif dari templat.
9+
Pada banyak kasus, Vue menganjurkan penggunaan templat untuk membuat HTML. Tetapi, ada beberapa situasi di mana anda butuh menggunakan Javascript secara penuh. Anda bisa menggunakan **fungsi render**, sebagai alternatif dari templat.
1010

1111
Mari Lihat contoh sederhana di mana fungsi 'render' terlihat praktis. Katakanlah anda ingin menghasilkan *anchored headings*:
1212

@@ -103,9 +103,9 @@ Bentuk pohon dari *DOM nodes* untuk HTML di atas terlihat seperti:
103103

104104
![Visualisasi pohon *DOM*](/images/dom-tree.png)
105105

106-
Setiap elemen adalah *node*. Setiap teks adalah node. BAhkan komentar juga *node*!. Dan sama seperti silsilah keluarga, setiap *node* bisa memiliki anak (misalnya setiap node mengandung *node* lainnya).
106+
Setiap elemen adalah *node*. Setiap teks adalah *node*. BAhkan komentar juga *node*!. Dan sama seperti silsilah keluarga, setiap *node* bisa memiliki anak (misalnya setiap *node* mengandung *node* lainnya).
107107

108-
Memperbarui *node* yang banyak ini secara eisien tidaklah mudah, tapi untungnya, anda tidak harus melakukannya secara manual. Sebaliknya, gunakan Vue untuk membuat HTML yang kalian inginkan melalui templat:
108+
Memperbarui *node* yang banyak ini secara eisien tidaklah mudah, tapi untungnya, anda tidak harus melakukannya secara manual. Sebaliknya, gunakan Vue untuk membuat HTML yang Anda inginkan melalui templat:
109109

110110
```html
111111
<h1>{{ blogTitle }}</h1>
@@ -129,7 +129,7 @@ Vue melakukannya dengan cara membuat **virtual DOM** untuk mencatat perubahan ya
129129
return createElement('h1', this.blogTitle)
130130
```
131131

132-
Apa yang sebenarnya `createElement` kembalikan? hal itu bukanlah elemen DOM yang benar-benar diproses oleh browser. Secara teknis, lebih akurat jika dinamakan `createNodeDescription`, karena berisi informasi yang dibutuhkan oleh Vue, jenis node apa yang harus ditampilkan; termasuk deskripsi ini dari node tersebut. Deskripsi node ini diistilahkan dengan "virtual node", biasanya disingkat **VNode**. Sedangkan "Virtual DOM" digunakan untuk merujuk ke kumpulan dari VNode secara keseluruhan.
132+
Apa yang sebenarnya `createElement` kembalikan? hal itu bukanlah elemen DOM yang benar-benar diproses oleh browser. Secara teknis, lebih akurat jika dinamakan `createNodeDescription`, karena berisi informasi yang dibutuhkan oleh Vue, jenis *node* apa yang harus ditampilkan; termasuk deskripsi ini dari *node* tersebut. Deskripsi *node* ini diistilahkan dengan "virtual *node*", biasanya disingkat **VNode**. Sedangkan "Virtual DOM" digunakan untuk merujuk ke kumpulan dari VNode secara keseluruhan.
133133

134134
## Argumen `createElement`
135135

@@ -138,16 +138,16 @@ Untuk lebih mendalami bagaimana cara penggunaan fitur templat di fungsi `createE
138138
``` js
139139
// @returns {VNode}
140140
createElement(
141-
// {String | Object | Function}
141+
// {String | Obyek | Function}
142142
// Nama tag HTML, opsi komponen, atau fungsi asinkronus
143143
// Fungsi resolving ke salah satu. Wajib.
144144
'div',
145145

146-
// {Object}
146+
// {Obyek}
147147
// Objek data yang terkait dengan atribut
148148
// Anda akan gunakan dalam templat. Opsional.
149149
{
150-
// (lihat detail di bagian selanjutnya)
150+
// (lihat detil di bagian selanjutnya)
151151
},
152152

153153
// {String | Array}
@@ -165,9 +165,9 @@ createElement(
165165
)
166166
```
167167

168-
### The Data Object In-Depth
168+
### Obyek Data Secara Mendalam
169169

170-
Penting untuk dicatat, sama halnya `v-bind:class` dan `v-bind:style` diperlakukan secara khusus di templat, mereka punya tempat tersendiri juga di objek data dari VNode. Lewat objek ini kalian juga melakukan proses *binding* ke atribut bawaan HTML juga properti DOM seperti `innerHTML` (menggantikan direktif `v-html`):
170+
Penting untuk dicatat, sama halnya `v-bind:class` dan `v-bind:style` diperlakukan secara khusus di templat, mereka punya tempat tersendiri juga di objek data dari VNode. Lewat objek ini Anda juga melakukan proses *binding* ke atribut bawaan HTML juga properti DOM seperti `innerHTML` (menggantikan direktif `v-html`):
171171

172172
``` js
173173
{
@@ -232,7 +232,7 @@ Penting untuk dicatat, sama halnya `v-bind:class` dan `v-bind:style` diperlakuka
232232
// Properti khusus lainnya
233233
key: 'myKey',
234234
ref: 'myRef',
235-
// Jika kalian menggunakan nama ref yang sama
235+
// Jika Anda menggunakan nama ref yang sama
236236
// di beberapa tempat, nilai dari `$refs.myRef` akan berbentuk
237237
// array
238238
refInFor: true
@@ -297,7 +297,7 @@ render: function (createElement) {
297297
}
298298
```
299299

300-
Jika kalian memang ingin menduplikasi elemen/komponen yang sama beberapa kali, kalian bisa menggunakan fungsi *factory*. Di bawah ini adalah contoh yang valid untuk menampilkan 20 paragraf yang sama:
300+
Jika Anda memang ingin menduplikasi elemen/komponen yang sama beberapa kali, Anda bisa menggunakan fungsi *factory*. Di bawah ini adalah contoh yang valid untuk menampilkan 20 paragraf yang sama:
301301

302302
``` js
303303
render: function (createElement) {
@@ -339,7 +339,7 @@ render: function (createElement) {
339339

340340
### `v-model`
341341

342-
Tidak ada fitur yang mirip `v-model` di fungsi render, kalian harus menerapkannya sendiri:
342+
Tidak ada fitur yang mirip `v-model` di fungsi render, Anda harus menerapkannya sendiri:
343343

344344
``` js
345345
props: ['value'],
@@ -358,7 +358,7 @@ render: function (createElement) {
358358
}
359359
```
360360

361-
Mungkin terasa lebih susah, tapi kalian punya kendali penuh dibandingkan `v-model`.
361+
Mungkin terasa lebih susah, tapi Anda punya kendali penuh dibandingkan `v-model`.
362362

363363
### *Event* & *Key Modifiers*
364364

@@ -381,7 +381,7 @@ on: {
381381
}
382382
```
383383

384-
Untuk event dan key modifier lainnya, tidak ada prefix yang dibutuhkan, cukup gunakan event method-nya di handler:
384+
Untuk event dan key modifier lainnya, tidak ada prefix yang dibutuhkan, cukup gunakan event metode-nya di handler:
385385

386386
| Modifier(s) | Equivalent in Handler |
387387
| ------ | ------ |
@@ -414,7 +414,7 @@ on: {
414414

415415
### Slot
416416

417-
Kalian bisa mengakses isi slot statik sebagai array VNode dari [`this.$slots`](../api/#vm-slots):
417+
Anda bisa mengakses isi slot statik sebagai array VNode dari [`this.$slots`](../api/#vm-slots):
418418

419419
``` js
420420
render: function (createElement) {
@@ -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 Anda menulis fungsi `render` yang panjang, akan menyusahkan jika Anda 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 Anda 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 ES2015 yang berisi JSX, sehingga Anda bisa menghapus bagian parameter `(h)`. Di versi sebelumnya, akan terjadi galat 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 siklus hidup. 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 Anda ingin komponen fungsional Anda menerima props. Di versi 2.3.0 ke atas, Anda 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 Anda 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 Anda menambahkan argumen `context`, mengubah `this.$slots.default` menjadi `context.children`, lalu mengubah `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, Anda 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`. Anda 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 Anda menggunakan komponen fungsional berbasis templat, Anda harus meneruskan atribut dan listener secara manual. Anda 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 Anda penasaran kenapa kita butuh `slots()` dan `children`. 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()` memungkinkan Anda untuk memilih apakah komponen tahu tentang sistem slot, atau mungkin hanya ingin mendelegasikan tanggung jawab itu ke komponen lain dengan 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+
Anda mungkin penasaran, bagaimana caranya templat Vue bisa diubah menjadi fungsi render. Detil implementasi ini tidak wajib untuk diketahui. Tapi jika Anda penasaran, di bawah ini adalah demo menggunakan `Vue.compile` untuk secara langsung mengubah string templat menjadi fungsi render:
641641

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

0 commit comments

Comments
 (0)