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

Time:03-29

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?

I tried this without success:

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

CodePudding user response:

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()
  • Related