He creado un campo de entrada y le he dado un ref="inputField" así
<input ref="inputField"> <button @click="btn">Click</button>Al hacer clic, quiero agregarle enfoque y he escrito el código de esta manera
<script> methods:{ btn(){ this.$refs.inputField.focus() } } </script>Pero esto no funciona. ¿Alguien puede explicar cómo hacer una entrada en el foco cuando se hace clic en el botón? Lo quiero cuando se hace clic en el botón.
Tu código funciona. Vea este ejemplo .
Sin embargo, al menos necesita export default :
<script> export default { methods: { btn() { this.$refs.inputField.focus() } } } </script>