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.
Your code works. See this example.
You do at least need export default though:
<script>
export default {
methods: {
btn() {
this.$refs.inputField.focus()
}
}
}
</script>