Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Why does this.$refs.inuputField'.focus() not work in Vue?

I have created an input field and given it a ref="inputField" like so

<input ref="inputField">
<button @click="btn">Click</button>

On click I want to add focus to it and I have written the code like this

<script>
 methods:{

btn(){
this.$refs.inputField.focus()
}
}
</script>

but this does not work. Can anyone please explain how to make an input on focus when button is clicked. I want it when the button is clicked.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your code works. See this example.

You do at least need export default though:

<script>
 export default {
    methods: {
      btn() {
        this.$refs.inputField.focus()
      }
    }
  }
</script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!