Skip to content

Commit 6b79a13

Browse files
gustialfianmazipan
authored andcommitted
Menerjemahkan Direktif Khusus (vuejs#82)
* intial draft * update - Direktif Khusus -> Direktif Kustom - type standar -> standard * Update src/v2/guide/custom-directive.md Co-Authored-By: gustialfian <[email protected]> * Update src/v2/guide/custom-directive.md Co-Authored-By: gustialfian <[email protected]> * Update src/v2/guide/custom-directive.md Co-Authored-By: gustialfian <[email protected]> * Update src/v2/guide/custom-directive.md Co-Authored-By: gustialfian <[email protected]> * preposisi
1 parent 300c5e4 commit 6b79a13

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

src/v2/guide/custom-directive.md

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Custom Directives
2+
title: Direktif Kustom
33
type: guide
44
order: 302
55
---
66

7-
## Intro
7+
## Pendahuluan
88

9-
In addition to the default set of directives shipped in core (`v-model` and `v-show`), Vue also allows you to register your own custom directives. Note that in Vue 2.0, the primary form of code reuse and abstraction is components - however there may be cases where you need some low-level DOM access on plain elements, and this is where custom directives would still be useful. An example would be focusing on an input element, like this one:
9+
Selain kumpulan direktif standard (`v-model` dan `v-show`), Vue juga memperbolehkan Anda untuk mendaftarkan direktif kustom milik Anda. Perhatikan bahwa dalam Vue 2.0, bentuk utama dari penggunaan kembali dan abstraksi kode adalah komponen - namun mungkin ada kasus dimana Anda memerlukan akses DOM tingkat rendah pada elemen polos, dan di sini dimana direktif kustom akan tetap bermanfaat. Contoh fokus kepada elemen input, seperti satu ini:
1010

1111
{% raw %}
1212
<div id="simplest-directive-example" class="demo">
@@ -24,74 +24,77 @@ new Vue({
2424
</script>
2525
{% endraw %}
2626

27-
When the page loads, that element gains focus (note: `autofocus` doesn't work on mobile Safari). In fact, if you haven't clicked on anything else since visiting this page, the input above should be focused now. Now let's build the directive that accomplishes this:
27+
Saat halaman dimuat, elemen tersebut akan mendapatkan fokus (perhatikan: `autofocus` tidak bekerja pada Safari seluler). Faktanya, jika Anda belum mengklik hal lain sejak mengunjungi halaman ini, input di atas seharusnya sudah fokus sekarang. Sekarang mari kita bangung direktif yang mencapai hal ini:
2828

2929
``` js
30-
// Register a global custom directive called `v-focus`
30+
// Mendaftarkan sebuah direktif kustom dengan nama `v-focus`
3131
Vue.directive('focus', {
32-
// When the bound element is inserted into the DOM...
32+
// Saat elemen yang terikat dimasukan ke dalam DOM...
3333
inserted: function (el) {
34-
// Focus the element
34+
// Fokus terhadap elemen
3535
el.focus()
3636
}
3737
})
3838
```
3939

40-
If you want to register a directive locally instead, components also accept a `directives` option:
40+
Jika Anda ingin mendaftarkan direktif secara lokal, komponen juga menerima opsi `directives`:
4141

4242
``` js
4343
directives: {
4444
focus: {
45-
// directive definition
45+
// definisi direktif
4646
inserted: function (el) {
4747
el.focus()
4848
}
4949
}
5050
}
5151
```
5252

53-
Then in a template, you can use the new `v-focus` attribute on any element, like this:
53+
Kemudian di templat, Anda dapat menggunakan atribut `v-focus` baru pada elemen apa pun, seperti ini:
54+
5455

5556
``` html
5657
<input v-focus>
5758
```
59+
60+
## Fungsi Kait
61+
62+
Objek definisi direktif dapat menyediakan beberapa fungsi kait (semua opsional):
5863

59-
## Hook Functions
6064

61-
A directive definition object can provide several hook functions (all optional):
65+
- `bind`: dipanggil hanya sekali, saat direktif partama kali terikat dengan elemen. Di sini Anda dapat melakukan pekerjaan pengaturan satu kali.
6266

63-
- `bind`: called only once, when the directive is first bound to the element. This is where you can do one-time setup work.
67+
- `inserted`: dipanggil ketika elemen terikat telah dimasukkan ke dalam *node* induknya (ini hanya menjamin keberadaan *node* induknya, tidak harus dalam dokumen).
6468

65-
- `inserted`: called when the bound element has been inserted into its parent node (this only guarantees parent node presence, not necessarily in-document).
69+
- `update`: dipanggil ketika komponen yang memuat *VNode* telah diperbarui, __tetapi mungkin sebelum anak-anaknya diperbarui__. Nilai direktif ini mungkin berubah atau mungkin tidak berubah, tetapi Anda dapat melewati pembaruan yang tidak perlu dengan membandingkan nilai saat ini dan lama (lihat di bawah ini pada argumen hook).
6670

67-
- `update`: called after the containing component's VNode has updated, __but possibly before its children have updated__. The directive's value may or may not have changed, but you can skip unnecessary updates by comparing the binding's current and old values (see below on hook arguments).
71+
<p class="tip">Kami akan membahas VNodes secara lebih rinci [nanti](./render-function.html#The-Virtual-DOM), ketika kita membahas [fungsi render](./render-function.html).</p>
6872

69-
<p class="tip">We'll cover VNodes in more detail [later](./render-function.html#The-Virtual-DOM), when we discuss [render functions](./render-function.html).</p>
73+
- `componentUpdated`: dipanggil setelah komponen yang memuat *VNode* __dan *VNodes* anak-anaknya__ telah diperbarui.
7074

71-
- `componentUpdated`: called after the containing component's VNode __and the VNodes of its children__ have updated.
75+
- `unbind`: dipanggil hanya sekali, ketika direktif terlepas dari elemennya.
7276

73-
- `unbind`: called only once, when the directive is unbound from the element.
77+
Kita akan menjelajahi argumen yang dioper ke kait ini (mis. `el`,` binding`, `vnode`, dan` oldVnode`) di bagian berikutnya.
7478

75-
We'll explore the arguments passed into these hooks (i.e. `el`, `binding`, `vnode`, and `oldVnode`) in the next section.
7679

77-
## Directive Hook Arguments
80+
## Argumen Kait Direktif
7881

79-
Directive hooks are passed these arguments:
82+
Kait direktif dioper argumen ini:
8083

81-
- `el`: The element the directive is bound to. This can be used to directly manipulate the DOM.
82-
- `binding`: An object containing the following properties.
83-
- `name`: The name of the directive, without the `v-` prefix.
84-
- `value`: The value passed to the directive. For example in `v-my-directive="1 + 1"`, the value would be `2`.
85-
- `oldValue`: The previous value, only available in `update` and `componentUpdated`. It is available whether or not the value has changed.
86-
- `expression`: The expression of the binding as a string. For example in `v-my-directive="1 + 1"`, the expression would be `"1 + 1"`.
87-
- `arg`: The argument passed to the directive, if any. For example in `v-my-directive:foo`, the arg would be `"foo"`.
88-
- `modifiers`: An object containing modifiers, if any. For example in `v-my-directive.foo.bar`, the modifiers object would be `{ foo: true, bar: true }`.
89-
- `vnode`: The virtual node produced by Vue's compiler. See the [VNode API](../api/#VNode-Interface) for full details.
90-
- `oldVnode`: The previous virtual node, only available in the `update` and `componentUpdated` hooks.
84+
- `el`: Elemen dimana direktif terikat. Ini dapat digunakan secara langsung untuk memanipulasi DOM.
85+
- `binding`: Objek yang berisi properti berikut.
86+
- `name`: Nama direktif, tanpa awalan `v-`.
87+
- `value`: Nilai yang dioper ke direktif. Misalnya pada `v-my-directive="1 + 1"`, nilainya akan menjadi `2`.
88+
- `oldValue`: Nilai sebelumnya, hanya tersedia pada `update` dan `componentUpdated`. Tersedia apakah nilai telah berubah atau tidak.
89+
- `expression`: Ekspresi dari *binding* sebagai *string*. Misalnya pada `v-my-directive="1 + 1"`, ekspresi akan menjadi `"1 + 1"`.
90+
- `arg`: Argumen yang dioper ke direktif, jika ada. Misalnya pada `v-my-directive:foo`, argumen akan menjandi `"foo"`.
91+
- `modifiers`: Objek yang memuat pengubah, jika ada. Misalnya pada `v-my-directive.foo.bar`, objek pengubah menjadi `{ foo: true, bar: true }`.
92+
- `vnode`: *Node* virtual yang dibuat oleh penyusun Vue. Lihat [API VNode](../api/#VNode-Interface) untuk detil lebih lengkap.
93+
- `oldVnode`: Virtual *node* sebelumnya, hanya tersedia pada kait `update` dan `componentUpdated`.
9194

92-
<p class="tip">Apart from `el`, you should treat these arguments as read-only and never modify them. If you need to share information across hooks, it is recommended to do so through element's [dataset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset).</p>
95+
<p class="tip">Terlepas dari `el`, Anda harus memperlakukan argumen ini sebagai hanya-baca dan tidak pernah memodifikasinya. Jika Anda perlu berbagi informasi lintas kait, direkomendasikan untuk melakukannya memlalui elemen [dataset](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset).</p>
9396

94-
An example of a custom directive using some of these properties:
97+
Contoh direktif kustom menggunakan beberapa properti ini:
9598

9699
``` html
97100
<div id="hook-arguments-example" v-demo:foo.a.b="message"></div>
@@ -143,19 +146,19 @@ new Vue({
143146
</script>
144147
{% endraw %}
145148

146-
## Function Shorthand
149+
## Fungsi Singkatan
147150

148-
In many cases, you may want the same behavior on `bind` and `update`, but don't care about the other hooks. For example:
151+
Dalam banyak kasus, Anda mungkin menginginkan perilaku yang sama pada `bind` dan` update`, tetapi tidak peduli dengan kait lainnya. Sebagai contoh:
149152

150153
``` js
151154
Vue.directive('color-swatch', function (el, binding) {
152155
el.style.backgroundColor = binding.value
153156
})
154157
```
155158

156-
## Object Literals
159+
## Objek Literal
157160

158-
If your directive needs multiple values, you can also pass in a JavaScript object literal. Remember, directives can take any valid JavaScript expression.
161+
Jika direktif yang Anda perlukan memerlukan beberapa nilai, Anda dapat mengirimkan objek JavaScript literal. Ingat, direktif dapat mengambil ekspresi JavaScript yang valid.
159162

160163
``` html
161164
<div v-demo="{ color: 'white', text: 'hello!' }"></div>

0 commit comments

Comments
 (0)