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/v2/guide/render-function.md
+53-53
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ order: 303
6
6
7
7
## Basics
8
8
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.
10
10
11
11
Mari Lihat contoh sederhana di mana fungsi 'render' terlihat praktis. Katakanlah anda ingin menghasilkan *anchored headings*:
12
12
@@ -103,9 +103,9 @@ Bentuk pohon dari *DOM nodes* untuk HTML di atas terlihat seperti:
103
103
104
104

105
105
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).
107
107
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:
109
109
110
110
```html
111
111
<h1>{{ blogTitle }}</h1>
@@ -129,7 +129,7 @@ Vue melakukannya dengan cara membuat **virtual DOM** untuk mencatat perubahan ya
129
129
returncreateElement('h1', this.blogTitle)
130
130
```
131
131
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.
133
133
134
134
## Argumen `createElement`
135
135
@@ -138,16 +138,16 @@ Untuk lebih mendalami bagaimana cara penggunaan fitur templat di fungsi `createE
138
138
```js
139
139
// @returns {VNode}
140
140
createElement(
141
-
// {String | Object | Function}
141
+
// {String | Obyek | Function}
142
142
// Nama tag HTML, opsi komponen, atau fungsi asinkronus
143
143
// Fungsi resolving ke salah satu. Wajib.
144
144
'div',
145
145
146
-
// {Object}
146
+
// {Obyek}
147
147
// Objek data yang terkait dengan atribut
148
148
// Anda akan gunakan dalam templat. Opsional.
149
149
{
150
-
// (lihat detail di bagian selanjutnya)
150
+
// (lihat detil di bagian selanjutnya)
151
151
},
152
152
153
153
// {String | Array}
@@ -165,9 +165,9 @@ createElement(
165
165
)
166
166
```
167
167
168
-
### The Data Object In-Depth
168
+
### Obyek Data Secara Mendalam
169
169
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`):
171
171
172
172
```js
173
173
{
@@ -232,7 +232,7 @@ Penting untuk dicatat, sama halnya `v-bind:class` dan `v-bind:style` diperlakuka
232
232
// Properti khusus lainnya
233
233
key:'myKey',
234
234
ref:'myRef',
235
-
// Jika kalian menggunakan nama ref yang sama
235
+
// Jika Anda menggunakan nama ref yang sama
236
236
// di beberapa tempat, nilai dari `$refs.myRef` akan berbentuk
237
237
// array
238
238
refInFor:true
@@ -297,7 +297,7 @@ render: function (createElement) {
297
297
}
298
298
```
299
299
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:
301
301
302
302
```js
303
303
render:function (createElement) {
@@ -339,7 +339,7 @@ render: function (createElement) {
339
339
340
340
### `v-model`
341
341
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:
343
343
344
344
```js
345
345
props: ['value'],
@@ -358,7 +358,7 @@ render: function (createElement) {
358
358
}
359
359
```
360
360
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`.
362
362
363
363
### *Event* & *Key Modifiers*
364
364
@@ -381,7 +381,7 @@ on: {
381
381
}
382
382
```
383
383
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:
385
385
386
386
| Modifier(s) | Equivalent in Handler |
387
387
| ------ | ------ |
@@ -414,7 +414,7 @@ on: {
414
414
415
415
### Slot
416
416
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):
418
418
419
419
```js
420
420
render:function (createElement) {
@@ -457,7 +457,7 @@ render: function (createElement) {
457
457
458
458
## JSX
459
459
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:
461
461
462
462
```js
463
463
createElement(
@@ -472,15 +472,15 @@ createElement(
472
472
)
473
473
```
474
474
475
-
Especially when the template version is so simple in comparison:
475
+
Terutama jika versi templatnya lebih sederhana:
476
476
477
477
```html
478
478
<anchored-heading:level="1">
479
479
<span>Hello</span> world!
480
480
</anchored-heading>
481
481
```
482
482
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:
484
484
485
485
```js
486
486
importAnchoredHeadingfrom'./AnchoredHeading.vue'
@@ -497,61 +497,61 @@ new Vue({
497
497
})
498
498
```
499
499
500
-
<pclass="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
+
<pclass="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>
501
501
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).
503
503
504
-
## Functional Components
504
+
## Komponen Fungsional
505
505
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*.
507
507
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:
509
509
510
510
```js
511
511
Vue.component('my-component', {
512
512
functional:true,
513
-
// Props are optional
513
+
// Props bersifat opsional
514
514
props: {
515
515
// ...
516
516
},
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
519
519
render:function (createElement, context) {
520
520
// ...
521
521
}
522
522
})
523
523
```
524
524
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*.
526
526
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:
528
528
529
529
```html
530
530
<templatefunctional>
531
531
</template>
532
532
```
533
533
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:
535
535
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.
544
544
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`.
546
546
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).
548
548
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:
550
550
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
553
553
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:
### Passing Attributes and Events to Child Elements/Components
591
+
### Meneruskan Atribut dan Event ke Anak Komponen
592
592
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.
594
594
595
-
Functional components, however, require you to explicitly define this behavior:
595
+
Tetapi untuk komponen fungsional, Anda harus secara tertulis mendefinisikannya:
596
596
597
597
```js
598
598
Vue.component('my-functional-button', {
599
599
functional:true,
600
600
render:function (createElement, context) {
601
-
//Transparently pass any attributes, event listeners, children, etc.
601
+
//Teruskan atribut, event listener, anak, dan sebagainya.
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`.
608
608
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.
610
610
611
611
```html
612
612
<templatefunctional>
@@ -622,7 +622,7 @@ If you are using template-based functional components, you will also have to man
622
622
623
623
### `slots()` vs `children`
624
624
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?
626
626
627
627
```html
628
628
<my-functional-component>
@@ -633,11 +633,11 @@ You may wonder why we need both `slots()` and `children`. Wouldn't `slots().defa
633
633
</my-functional-component>
634
634
```
635
635
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`.
637
637
638
-
## Template Compilation
638
+
## Kompilasi Templat
639
639
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:
0 commit comments