Sai Karthik

Balancing the braces ...

Reset HTML Forms Using Vue Refs

August 11, 2023 | 1 minute read

Vue refs come handly when we want to access DOM elements directly. You can read more about vue refs here

In this case, we want to reset a form. So, let’s assign a html attribute named ref to a <form> tag

A simple example:

1
2
3
<form ref="myForm">
    <input></input>
</form>

Now we can apply DOM methods to an element like reset() on this form by calling this.$refs.myForm.reset()

Share via: Email |
Tags: vue