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
* translate event handling page
* fix typo and grammar
* improvement from feedback
* - change word "key" to italic
- change word "browser" to "peramban"
* - change word "statement" to statemen
- change word "browser" to peramban
<p>Tombol diatas telah ditekan {{ counter }} kali.</p>
17
17
</div>
18
18
```
19
19
```js
20
-
varexample1=newVue({
21
-
el:'#example-1',
20
+
varcontoh1=newVue({
21
+
el:'#contoh-1',
22
22
data: {
23
23
counter:0
24
24
}
25
25
})
26
26
```
27
27
28
-
Result:
28
+
Hasil:
29
29
30
30
{% raw %}
31
-
<divid="example-1"class="demo">
31
+
<divid="contoh-1"class="demo">
32
32
<buttonv-on:click="counter += 1">Add 1</button>
33
-
<p>The button above has been clicked {{ counter }} times.</p>
33
+
<p>Tombol diatas telah ditekan {{ counter }} kali.</p>
34
34
</div>
35
35
<script>
36
-
varexample1=newVue({
37
-
el:'#example-1',
36
+
varcontoh1=newVue({
37
+
el:'#contoh-1',
38
38
data: {
39
39
counter:0
40
40
}
41
41
})
42
42
</script>
43
43
{% endraw %}
44
44
45
-
## Method Event Handlers
45
+
## Metode Event Handler
46
46
47
-
The logic for many event handlers will be more complex though, so keeping your JavaScript in the value of the `v-on`attribute isn't feasible. That's why`v-on`can also accept the name of a method you'd like to call.
47
+
Bagaimanapun Logika untuk banyak _event__handler_ akan terlihat rumit, jadi menempatkan kode JavaScript Anda dalam atribut `v-on`tidaklah tepat. Itulah mengapa`v-on`dapat juga menerima nama metode yang ingin dijalankan.
48
48
49
-
For example:
49
+
Contoh:
50
50
51
51
```html
52
-
<divid="example-2">
53
-
<!-- `greet` is the name of a method defined below-->
52
+
<divid="contoh-2">
53
+
<!-- `greet` adalah nama metode yang telah didefinisikan di bawah-->
54
54
<buttonv-on:click="greet">Greet</button>
55
55
</div>
56
56
```
57
57
58
58
```js
59
-
varexample2=newVue({
60
-
el:'#example-2',
59
+
varcontoh2=newVue({
60
+
el:'#contoh-2',
61
61
data: {
62
62
name:'Vue.js'
63
63
},
64
-
//define methods under the `methods` object
64
+
//mendefinisikan metode dibawah `methods` object
65
65
methods: {
66
66
greet:function (event) {
67
-
// `this` inside methods points to the Vue instance
67
+
// `this` di dalam metode merujuk ke Vue instance
68
68
alert('Hello '+this.name+'!')
69
-
// `event` is the native DOM event
69
+
// `event` adalah bawaan DOM event
70
70
if (event) {
71
71
alert(event.target.tagName)
72
72
}
73
73
}
74
74
}
75
75
})
76
76
77
-
//you can invoke methods in JavaScript too
78
-
example2.greet() // => 'Hello Vue.js!'
77
+
//Anda juga dapat memanggil metode dalam JavaScript
78
+
contoh2.greet() // => 'Hello Vue.js!'
79
79
```
80
80
81
-
Result:
81
+
Hasil:
82
82
83
83
{% raw %}
84
-
<divid="example-2"class="demo">
84
+
<divid="contoh-2"class="demo">
85
85
<buttonv-on:click="greet">Greet</button>
86
86
</div>
87
87
<script>
88
-
varexample2=newVue({
89
-
el:'#example-2',
88
+
varcontoh2=newVue({
89
+
el:'#contoh-2',
90
90
data: {
91
91
name:'Vue.js'
92
92
},
@@ -102,19 +102,19 @@ var example2 = new Vue({
102
102
</script>
103
103
{% endraw %}
104
104
105
-
## Methods in Inline Handlers
105
+
## Metode dalam Handler Sebaris
106
106
107
-
Instead of binding directly to a method name, we can also use methods in an inline JavaScript statement:
107
+
Dari pada menempatkan nama metode secara langsung, kita juga dapat menggunakan metode dalam sebuah JavaScript statemen sebaris:
108
108
109
109
```html
110
-
<divid="example-3">
110
+
<divid="contoh-3">
111
111
<buttonv-on:click="say('hi')">Say hi</button>
112
112
<buttonv-on:click="say('what')">Say what</button>
113
113
</div>
114
114
```
115
115
```js
116
116
newVue({
117
-
el:'#example-3',
117
+
el:'#contoh-3',
118
118
methods: {
119
119
say:function (message) {
120
120
alert(message)
@@ -123,7 +123,7 @@ new Vue({
123
123
})
124
124
```
125
125
126
-
Result:
126
+
Hasil:
127
127
{% raw %}
128
128
<divid="example-3"class="demo">
129
129
<buttonv-on:click="say('hi')">Say hi</button>
@@ -141,7 +141,7 @@ new Vue({
141
141
</script>
142
142
{% endraw %}
143
143
144
-
Sometimes we also need to access the original DOM event in an inline statement handler. You can pass it into a method using the special `$event`variable:
144
+
Terkadang kita juga butuh akses ke event DOM bawaan dalam statemen _handler_ sebaris. Anda dapat menempatkan variabel khusus `$event`ke dalam sebuah metode:
145
145
146
146
```html
147
147
<buttonv-on:click="warn('Form cannot be submitted yet.', $event)">
@@ -153,18 +153,18 @@ Sometimes we also need to access the original DOM event in an inline statement h
153
153
// ...
154
154
methods: {
155
155
warn:function (message, event) {
156
-
//now we have access to the native event
156
+
//sekarang kita memiliki akses ke event bawaan
157
157
if (event) event.preventDefault()
158
158
alert(message)
159
159
}
160
160
}
161
161
```
162
162
163
-
## Event Modifiers
163
+
## Pengubah (Modifier) Event
164
164
165
-
It is a very common need to call `event.preventDefault()`or`event.stopPropagation()`inside event handlers. Although we can do this easily inside methods, it would be better if the methods can be purely about data logic rather than having to deal with DOM event details.
165
+
Merupakan kebutuhan umum memanggil `event.preventDefault()`atau`event.stopPropagation()`di dalam event _handler_. Meskipun kita dapat melakukannya dengan mudah di dalam metode, akan lebih baik jika metode murni hanya berisi logika data dari pada menangani rincian event DOM.
166
166
167
-
To address this problem, Vue provides **event modifiers**for`v-on`. Recall that modifiers are directive postfixes denoted by a dot.
167
+
Untuk menyelesaikan masalah ini, Vue menyediakan **pengubah event **untuk`v-on`. Penggunaan pengubah tersebut ialah dengan tambahan direktif diawali dengan simbol titik.
168
168
169
169
-`.stop`
170
170
-`.prevent`
@@ -174,115 +174,115 @@ To address this problem, Vue provides **event modifiers** for `v-on`. Recall tha
174
174
-`.passive`
175
175
176
176
```html
177
-
<!--the click event's propagation will be stopped-->
177
+
<!--perambatan event klik akan dihentikan-->
178
178
<av-on:click.stop="doThis"></a>
179
179
180
-
<!--the submit event will no longer reload the page-->
180
+
<!--event submit tidak lagi memuat ulang halaman-->
181
181
<formv-on:submit.prevent="onSubmit"></form>
182
182
183
-
<!--modifiers can be chained-->
183
+
<!--pengubah dapat ditulis berantai-->
184
184
<av-on:click.stop.prevent="doThat"></a>
185
185
186
-
<!--just the modifier-->
186
+
<!--sebuah pengubah-->
187
187
<formv-on:submit.prevent></form>
188
188
189
-
<!--use capture mode when adding the event listener -->
190
-
<!--i.e. an event targeting an inner element is handled here before being handled by that element-->
189
+
<!--gunakan mode capture saat menambahkan event listener -->
190
+
<!--sebagai contoh, sebuah event menargetkan sebuah inner elemen ditangani disini sebelum ditangani oleh elemen tesebut-->
191
191
<divv-on:click.capture="doThis">...</div>
192
192
193
-
<!--only trigger handler if event.target is the element itself-->
194
-
<!--i.e. not from a child element-->
193
+
<!--handler hanya dipicu jiks event.target adalah elemen itu sendiri-->
194
+
<!--sebagai contoh, tidak dari elemen anak-->
195
195
<divv-on:click.self="doThat">...</div>
196
196
```
197
197
198
-
<pclass="tip">Order matters when using modifiers because the relevant code is generated in the same order. Therefore using `v-on:click.prevent.self` will prevent **all clicks** while `v-on:click.self.prevent` will only prevent clicks on the element itself.</p>
198
+
<pclass="tip">Urutan penting saat menggunakan pengubah karena kode yang bersangkutan dibentuk dengan urutan yang sama. Maka dari itu, menggunakan `v-on:click.prevent.self` akan mencegah **semua klik** sementara `v-on:click.self.prevent` hanya akan mencegah klik pada elemen itu sendiri.</p>
199
199
200
-
> New in 2.1.4+
200
+
> Baru pada versi 2.1.4+
201
201
202
202
```html
203
-
<!--the click event will be triggered at most once-->
203
+
<!-- click event akan dipicu paling banyak sekali-->
204
204
<av-on:click.once="doThis"></a>
205
205
```
206
206
207
-
Unlike the other modifiers, which are exclusive to native DOM events, the `.once` modifier can also be used on [component events](components-custom-events.html). If you haven't read about components yet, don't worry about this for now.
207
+
Tidak seperti pengubah lainnya, yang khusus untuk event DOM bawaan, `.once` modifier juga dapat digunakan pada [komponen event](components-custom-events.html). Jika anda belum membaca tentang komponen, jangan khawatir tentang ini untuk sekarang.
208
208
209
-
> New in 2.3.0+
209
+
> Baru pada versi 2.3.0+
210
210
211
-
Vue also offers the`.passive` modifier, corresponding to [`addEventListener`'s `passive` option](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters).
211
+
Vue juga menawarkan pengubah`.passive`, sesuai dengan [opsi `addEventListener`'s `passive`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters).
212
212
213
213
```html
214
-
<!--the scroll event's default behavior (scrolling) will happen-->
215
-
<!--immediately, instead of waiting for `onScroll` to complete -->
216
-
<!--in case it contains `event.preventDefault()`-->
214
+
<!--perilaku bawaan event scroll (scrolling) akan terjadi-->
215
+
<!--segera, dari pada menunggu `onScroll` selesai-->
216
+
<!--jika memuat `event.preventDefault()` -->
217
217
<divv-on:scroll.passive="onScroll">...</div>
218
218
```
219
219
220
-
The`.passive`modifier is especially useful for improving performance on mobile devices.
220
+
pengubah`.passive`secara khusus berguna meningkatkan performa pada perangkat mobile.
221
221
222
-
<pclass="tip">Don't use `.passive` and `.prevent` together, because `.prevent` will be ignored and your browser will probably show you a warning. Remember, `.passive` communicates to the browser that you _don't_ want to prevent the event's default behavior.</p>
222
+
<pclass="tip">Jangan menggunakan `.passive` dan `.prevent` bersamaan, karena `.prevent` akan diabaikan dan peramban Anda kemungkinan akan menampilkan peringatan. Ingat, `.passive` berkomunikasi dengan peramban yang mana anda tidak ingin mencegah perilaku bawaan event.</p>
223
223
224
-
## Key Modifiers
224
+
## Pengubah (Modifier) Key
225
225
226
-
When listening for keyboard events, we often need to check for specific keys. Vue allows adding key modifiers for`v-on`when listening for key events:
226
+
Saat memantau keyboard event, kita sering membutuhkan untuk memeriksa _key_ tertentu. Vue mengizinkan penambahan pengubah _key_ untuk`v-on`saat memantau _key_ events:
227
227
228
228
```html
229
-
<!--only call `vm.submit()` when the `key` is `Enter` -->
229
+
<!--hanya memanggil `vm.submit()` saat `key` adalah `Enter` -->
230
230
<inputv-on:keyup.enter="submit">
231
231
```
232
232
233
-
You can directly use any valid key names exposed via [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)as modifiers by converting them to kebab-case.
233
+
Anda dapat secara langsung menggunakan nama _key_ yang valid via [`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)sebagai pengubah dengan mengubahnya ke kebab-case.
234
234
235
235
```html
236
236
<inputv-on:keyup.page-down="onPageDown">
237
237
```
238
238
239
-
In the above example, the handler will only be called if `$event.key`is equal to`'PageDown'`.
239
+
Pada contoh di atas, _handler_ hanya akan dipanggil jika `$event.key`sama dengan`'PageDown'`.
240
240
241
-
### Key Codes
241
+
### Key Code
242
242
243
-
<pclass="tip">The use of `keyCode` events [is deprecated](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) and may not be supported in new browsers.</p>
243
+
<pclass="tip">Penggunaan `keyCode` event [telah usang](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) dan mungkin tidak didukung pada peramban-peramban baru.</p>
244
244
245
-
Using `keyCode`attributes is also permitted:
245
+
Menggunakan atribut `keyCode`juga diperbolehkan:
246
246
247
247
```html
248
248
<inputv-on:keyup.13="submit">
249
249
```
250
250
251
-
Vue provides aliases for the most commonly used key codes when necessary for legacy browser support:
251
+
Vue menyediakan alias untuk _key_ code umum jika dibutuhkan untuk mendukung peramban lama:
252
252
253
253
-`.enter`
254
254
-`.tab`
255
-
-`.delete` (captures both "Delete" and "Backspace" keys)
255
+
-`.delete` (menangkap baik "Delete" dan "Backspace" _key_)
256
256
-`.esc`
257
257
-`.space`
258
258
-`.up`
259
259
-`.down`
260
260
-`.left`
261
261
-`.right`
262
262
263
-
<pclass="tip">A few keys (`.esc` and all arrow keys) have inconsistent `key` values in IE9, so these built-in aliases should be preferred if you need to support IE9.</p>
263
+
<pclass="tip">Beberapa kunci (.esc dan semua tombol arah) memiliki nilai _key_ yang tidak konsisten pada peramban IE9, jadi alias yang telah tersedia di atas lebih disarankan jika Anda butuh dukungan untuk peramban IE9.</p>
264
264
265
-
You can also [define custom key modifier aliases](../api/#keyCodes)via the global `config.keyCodes` object:
265
+
Anda juga dapat [mendefinisikan pengubah kustom alias key](../api/#keyCodes)melalui global config.keyCodes object:
266
266
267
267
```js
268
-
//enable `v-on:keyup.f1`
268
+
//Mengaktifkan `v-on:keyup.f1`
269
269
Vue.config.keyCodes.f1=112
270
270
```
271
271
272
-
## System Modifier Keys
272
+
## Sistem Pengubah (Modifier) Key
273
273
274
-
> New in 2.1.0+
274
+
> Baru pada versi 2.1.0+
275
275
276
-
You can use the following modifiers to trigger mouse or keyboard event listeners only when the corresponding modifier key is pressed:
276
+
Anda dapat menggunakan pengubah di bawah untuk memicu mouse atau keyboard event listener hanya pada saat pengubah tertentu ditekan:
277
277
278
278
-`.ctrl`
279
279
-`.alt`
280
280
-`.shift`
281
281
-`.meta`
282
282
283
-
> Note: On Macintosh keyboards, meta is the command key (⌘). On Windows keyboards, meta is the windows key (⊞). On Sun Microsystems keyboards, meta is marked as a solid diamond (◆). On certain keyboards, specifically MIT and Lisp machine keyboards and successors, such as the Knight keyboard, space-cadet keyboard, meta is labeled “META”. On Symbolics keyboards, meta is labeled “META” or “Meta”.
283
+
> Note: pada keyboard Macintosh, meta adalah command _key_ (⌘). Pada keyboard Windows, meta adalah Windows _key_(⊞). Pada keyboard Sun Microsystems, meta ditandai dengan solid diamond (◆). Pada keyboard tertentu, khususnya keyboard mesin MIT and Lisp dan penerusnya, seperti the Knight keyboard, space-cadet keyboard, meta diberi label “META”. Pada keyboard Symbolics, meta diberi label “META” atau “Meta”.
284
284
285
-
For example:
285
+
Contoh:
286
286
287
287
```html
288
288
<!-- Alt + C -->
@@ -292,41 +292,41 @@ For example:
292
292
<div@click.ctrl="doSomething">Do something</div>
293
293
```
294
294
295
-
<pclass="tip">Note that modifier keys are different from regular keys and when used with `keyup` events, they have to be pressed when the event is emitted. In other words, `keyup.ctrl` will only trigger if you release a key while holding down `ctrl`. It won't trigger if you release the `ctrl` key alone. If you do want such behaviour, use the `keyCode` for `ctrl` instead: `keyup.17`.</p>
295
+
<pclass="tip">Perhatikan bahwa pengubah _key_ berbeda dengan _key_ pada umumnya dan saat digunakan dengan `keyup` event, _key_ tersebut harus ditekan saat event dijalankan. Dengan kata lain, `keyup.ctrl` hanya akan dipicu ketika Anda melepas _key_ saat masih menekan `ctrl`. Hal tersebut tidak akan dipicu jika Anda melepas `ctrl` _key_ sendiri. Jika Anda tidak ingin perilaku seperti itu, gunakan `keyCode` untuk `ctrl` alih-alih: `keyup.17`.</p>
296
296
297
-
### `.exact` Modifier
297
+
### Pengubah (Modifier) `.exact`
298
298
299
-
> New in 2.5.0+
299
+
> Baru pada versi 2.5.0+
300
300
301
-
The`.exact`modifier allows control of the exact combination of system modifiers needed to trigger an event.
301
+
Pengubah`.exact`mengizinkan kontrol kombinasi eksak sistem pengubah yang dibutuhkan untuk memicu event.
302
302
303
303
```html
304
-
<!--this will fire even if Alt or Shift is also pressed-->
304
+
<!--baris ini akan mengeksekusi metode bahkan jika tombol Alt atau Shift juga ditekan-->
305
305
<button@click.ctrl="onClick">A</button>
306
306
307
-
<!--this will only fire when Ctrl and no other keys are pressed-->
307
+
<!--baris ini hanya akan mengeksekusi metode saat tombol Ctrl ditekan tanpa diikuti tombol lain-->
308
308
<button@click.ctrl.exact="onCtrlClick">A</button>
309
309
310
-
<!--this will only fire when no system modifiers are pressed-->
310
+
<!--baris ini hanya akan mengeksekusi metode saat tidak menekan sistem modifier keys-->
311
311
<button@click.exact="onClick">A</button>
312
312
```
313
313
314
-
### Mouse Button Modifiers
314
+
### Pengubah (Modifier) Tombol Mouse
315
315
316
-
> New in 2.2.0+
316
+
> Baru pada versi 2.2.0+
317
317
318
318
-`.left`
319
319
-`.right`
320
320
-`.middle`
321
321
322
-
These modifiers restrict the handler to events triggered by a specific mouse button.
322
+
Pengubah ini membatasi _handler_ pada event saat dipicu oleh tombol mouse tertentu.
323
323
324
-
## Why Listeners in HTML?
324
+
## Mengapa Listener di dalam HTML?
325
325
326
-
You might be concerned that this whole event listening approach violates the good old rules about "separation of concerns". Rest assured - since all Vue handler functions and expressions are strictly bound to the ViewModel that's handling the current view, it won't cause any maintenance difficulty. In fact, there are several benefits in using`v-on`:
326
+
Anda mungkin menyoroti bahwa keseluruhan pendekatan event listening menyalahi aturan lama tentang "separation of concerns". Kebanyakan meyakini itu - sejak semua fungsi-fungsi dan ekspresi Vue _handler_ terikat secara terbatas pada ViewModel yang mana menangani view yang berhubungan, hal itu tidak akan mempersulit pemeliharaan. Faktanya, terdapat beberapa keuntungan penggunaan`v-on`:
327
327
328
-
1.It's easier to locate the handler function implementations within your JS code by skimming the HTML template.
328
+
1.Mempermudah penempatan implementasi fungsi _handler_ diantara baris kode JS dengan menelusuri sekilas HTML templat.
329
329
330
-
2.Since you don't have to manually attach event listeners in JS, your ViewModel code can be pure logic and DOM-free. This makes it easier to test.
330
+
2.Sejak Anda tidak membutuhkan peletakkan event listeners dalam JS secara manual, baris kode ViewModel menjadi berisi murni logika dan bebas DOM. Ini memudahkan dalam pengujian.
331
331
332
-
3.When a ViewModel is destroyed, all event listeners are automatically removed. You don't need to worry about cleaning it up yourself.
332
+
3.Saat ViewModel dihapus, semua event listener secara otomatis dihapus. Anda tidak perlu khawatir tentang membersihkan event yang ada.
0 commit comments