3π
β
On the form element you can set a @submit.prevent="doSomething()"
to run a function when a button is clicked inside the form.
You can also set the button to type="button"
which will stop it from submitting the form. By default, any button in a <form>
tag will submit unless you define its type.
As shown below.
<form @submit.prevent="doSomething()">
...
<button type="button">Does Nothing</button>
<button type="submit">Submits the form by calling doSomething().</button>
<button>Submits the form by calling doSomething().</button>
</form>
<form>
...
<button type="button" @click="doSomething()">Only runs the function, does not submit the form.</button>
</form>
π€user5283119
Source:stackexchange.com