Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Do do I unfocus from an input in Vue.JS 2?

Let’s suppose I have an input like this:

<input type="text" v-model="x" ref="refInput">

If I want this input to focus programmatically, I can do:

this.$refs['refInput'].focus()

Is there a way to make the input lose the focus programmatically?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried this without success:

this.$refs['refInput'].unfocus()  // This does not work!

>Solution :

This is actually a simple JavaScript question. You focus on an input and leave focus with blur. What you need to do is to run the blur function.

example:

this.$refs.refInput.blur()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading