Vue.Js Focus input element


Vue.Js Focus input element It is very simple to focus on any input element in Vue.Js version 2.x. Here in this tutorial, we are going to explain how you can set focus on any input element in Vue.js.


Vue.Js Focus input element Example

You can set focus on Input element simply using directive-

JavaScript Part

Vue.Js Focus input element Example:

<script>
Vue.directive('focus', {
    inserted: function (el) {
        el.focus()
    }
});
</script>

Now you can use the above directive anywhere to set focus.

Html Part

JavaScript Set Focus Example:

<input v-focus>

Advertisements

Add Comment

📖 Read More