vue-autofocus-directive
Vue autofocus directive
34,248
| Install | |
|---|---|
npm install vue-autofocus-directive |
|
| Latest Version: | 1.0.5 |
| License: | MIT |
| Last Updated: | Aug 31, 2026 |
| Links: | npm |
Maintainer: bjornkrols
vue-autofocus-directive
Autofocus directive for Vue
About
Lifted from the official Vue tutorial: https://vuejs.org/v2/guide/custom-directive.html
When the page loads, the element with the directive gains focus (note: autofocus doesn’t work on mobile Safari).
Installation
npm install --save vue-autofocus-directive
Usage
import Vue from "vue";
import autofocus from "vue-autofocus-directive";
Vue.directive("autofocus", autofocus);
<input v-autofocus />
Options
binding
- Type:
value - Default:
undefined - Description: Required when using dynamic value
Example
<template>
<form>
<label>Email</label>
<input
v-autofocus
v-model="email"
type="email"
name="email"
placeholder="Email"
/>
</form>
</template>
or
<template>
<form>
<label>Email</label>
<input
v-autofocus="dynamicValue"
v-model="email"
type="email"
name="email"
placeholder="Email"
/>
</form>
</template>
<script>
export default {
data() {
return {
dynamicValue: false
};
}
};
</script>
Related Packages
Version History
| Version | Released | License |
|---|---|---|
| 1.0.5 | MIT | |
| 1.0.4 | MIT | |
| 1.0.3 | MIT | |
| 1.0.2 | MIT | |
| 1.0.1 | MIT | |
| 1.0.0 | MIT | |
| 0.0.5 | MIT | |
| 0.0.4 | MIT | |
| 0.0.3 | MIT | |
| 0.0.2 | MIT | |
| 0.0.1 | MIT | |
| 0.0.0 | MIT |