Skip to content

Commit 7d0ed2f

Browse files
authored
Use Enter and submit in keyboardEvent example (#1970)
1 parent 1b68103 commit 7d0ed2f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/v2/guide/events.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,18 @@ The `.passive` modifier is especially useful for improving performance on mobile
226226
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:
227227

228228
``` html
229-
<!-- only call `vm.submit()` when the `key` is PageDown -->
230-
<input @keyup.page-down="onPageDown">
229+
<!-- only call `vm.submit()` when the `key` is `Enter` -->
230+
<input v-on:keyup.enter="submit">
231231
```
232232

233-
In the above example, the handler will only be called if `$event.key` is equal to `'PageDown'`.
234-
235233
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.
236234

235+
``` html
236+
<input v-on:keyup.page-down="onPageDown">
237+
```
238+
239+
In the above example, the handler will only be called if `$event.key` is equal to `'PageDown'`.
240+
237241
### Key Codes
238242

239243
<p class="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>

0 commit comments

Comments
 (0)