[Vuejs]-Why the focus doesn't work when i click on input (Vue)?

3👍

You can use setTimeout to apply the focus, it’s not recommended but you can use it, as you have some specific use case here.

Here is the change required

focusField(name) {
            this.editField = name;
            setTimeout(()=>{
              this.$refs[name].focus(); // access the ref and make it focus after a delay make sure element appear in the DOM
            },200);
            
        },

You also need to change some of the method bindings from input, like a blur, when you are moving to any other element blur will call automatically.

Also declare all the ref for inputs elements.

Here is the stackblitz

Leave a comment