Skip to content

Commit bcb50f8

Browse files
ikrydevmazipan
authored andcommitted
Fungsi Render & JSX (#182)
* Dasar - Fungsi Render & JSX * Pengantar Nodes, Trees, dan Virtual DOM*
1 parent 758cfb3 commit bcb50f8

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/v2/guide/render-function.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
2-
title: Render Functions & JSX
2+
title: Fungsi *Render* % JSX
33
type: guide
44
order: 303
55
---
66

77
## Basics
88

9-
Vue recommends using templates to build your HTML in the vast majority of cases. There are situations however, where you really need the full programmatic power of JavaScript. That's where you can use the **render function**, a closer-to-the-compiler alternative to templates.
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.
1010

11-
Let's dive into a simple example where a `render` function would be practical. Say you want to generate anchored headings:
11+
Mari Lihat contoh sederhana di mana fungsi 'render' terlihat praktis. Katakanlah anda ingin menghasilkan *anchored headings*:
1212

1313
``` html
1414
<h1>
@@ -18,13 +18,13 @@ Let's dive into a simple example where a `render` function would be practical. S
1818
</h1>
1919
```
2020

21-
For the HTML above, you decide you want this component interface:
21+
Dari HTML di atas, anda memutuskan untuk menggunakan komponen di atas seperti:
2222

2323
``` html
2424
<anchored-heading :level="1">Hello world!</anchored-heading>
2525
```
2626

27-
When you get started with a component that only generates a heading based on the `level` prop, you quickly arrive at this:
27+
Ketika anda mulai dengan komponen yang hanya membuat *heading* berdasarkan properti `level`, hasilnya akan seperti ini:
2828

2929
``` html
3030
<script type="text/x-template" id="anchored-heading-template">
@@ -61,16 +61,17 @@ Vue.component('anchored-heading', {
6161
})
6262
```
6363

64-
That template doesn't feel great. It's not only verbose, but we're duplicating `<slot></slot>` for every heading level and will have to do the same when we add the anchor element.
64+
Templat di atas tidak telihat bagus, dan banyak sekali duplikasi di dalamnya seperti penggunaan `<slot></slot>` di setiap level heading dan harus melakukan hal yang sama ketika kita menambahkan elemen *anchor*.
65+
66+
Sementara templat bekerja dengan baik untuk sebagian besar komponen, jelas penggunaanya masih kurang tepat. Mari kita coba tulis ulang dengan menggunakan fungsi `render`:
6567

66-
While templates work great for most components, it's clear that this isn't one of them. So let's try rewriting it with a `render` function:
6768

6869
``` js
6970
Vue.component('anchored-heading', {
7071
render: function (createElement) {
7172
return createElement(
72-
'h' + this.level, // tag name
73-
this.$slots.default // array of children
73+
'h' + this.level, // nama tag
74+
this.$slots.default // isi dari komponen
7475
)
7576
},
7677
props: {
@@ -82,11 +83,11 @@ Vue.component('anchored-heading', {
8283
})
8384
```
8485

85-
Much simpler! Sort of. The code is shorter, but also requires greater familiarity with Vue instance properties. In this case, you have to know that when you pass children without a `slot` attribute into a component, like the `Hello world!` inside of `anchored-heading`, those children are stored on the component instance at `$slots.default`. If you haven't already, **it's recommended to read through the [instance properties API](../api/#Instance-Properties) before diving into render functions.**
86+
Lebih sederhana! kodenya lebih pendek, tapi kita juga harus terbiasa dengan properti yang ada di dalam *Vue instance*. Dalam kasus ini, anda harus tahu bahwa isi dari komponen yang tidak di tandai direktif `v-slot`, seperti `Hello World!` di dalam `anchored-heading`, isi tersebut disimpan di `$slots.default`. Jika anda masih belum paham, **direkomendasikan untuk membaca [instance properties API](../api/#Instance-Properties) sebelum mempelajari lebih dalam tentang fungsi render.**
8687

87-
## Nodes, Trees, and the Virtual DOM
88+
## *Nodes*, *Trees*, dan *Virtual DOM*
8889

89-
Before we dive into render functions, it’s important to know a little about how browsers work. Take this HTML for example:
90+
Sebelum kita lanjut lebih dalam tentang fungsi *render*, penting untuk sedikit mengetahui tentang bagaimana _browsers_ bekeerja. Lihat contoh HTM di bawah:
9091

9192
```html
9293
<div>
@@ -96,29 +97,29 @@ Before we dive into render functions, it’s important to know a little about ho
9697
</div>
9798
```
9899

99-
When a browser reads this code, it builds a [tree of "DOM nodes"](https://javascript.info/dom-nodes) to help it keep track of everything, just as you might build a family tree to keep track of your extended family.
100+
Ketika *browser* membaca kode di atas, *browser* akan membuat [pohon yang terdiri atas *DOM nodes*](https://javascript.info/dom-nodes) untuk membantu mencatat isi HTML tersebut, sama seperti jika anda membuat silsilah pohon keluarga untuk mencata isi dari keluarga anda.
100101

101-
The tree of DOM nodes for the HTML above looks like this:
102+
Bentuk pohon dari *DOM nodes* untuk HTML di atas terlihat seperti:
102103

103-
![DOM Tree Visualization](/images/dom-tree.png)
104+
![Visualisasi pohon *DOM*](/images/dom-tree.png)
104105

105-
Every element is a node. Every piece of text is a node. Even comments are nodes! A node is just a piece of the page. And as in a family tree, each node can have children (i.e. each piece can contain other pieces).
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).
106107

107-
Updating all these nodes efficiently can be difficult, but thankfully, you never have to do it manually. Instead, you tell Vue what HTML you want on the page, in a template:
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:
108109

109110
```html
110111
<h1>{{ blogTitle }}</h1>
111112
```
112113

113-
Or a render function:
114+
Atau fungsi *render*:
114115

115116
``` js
116117
render: function (createElement) {
117118
return createElement('h1', this.blogTitle)
118119
}
119120
```
120121

121-
And in both cases, Vue automatically keeps the page updated, even when `blogTitle` changes.
122+
Dalam kedua kasus, Vue secara otomatis akan memastikan bahwa tampilannya diperbarui dengan benar, seperti ketika `blogTitle` berubah.
122123

123124
### The Virtual DOM
124125

0 commit comments

Comments
 (0)