javascript / beginner
Snippet
Form Handling: .prevent Modifier
Event modifiers are shortcuts for common event handling logic. The .prevent modifier automatically calls event.preventDefault() to stop the browser from reloading.
snippet.js
1
2
3
<form @submit.prevent="submitData"><button type="submit">Save</button></form>
vue
Breakdown
1
@submit.prevent
Listens for the submit event and blocks the default browser action.
2
submitData
The function that will be executed when the form is submitted.