项目作者: byteboomers

项目描述 :
Vue autofocus directive
高级语言: JavaScript
项目地址: git://github.com/byteboomers/vue-autofocus-directive.git
创建时间: 2018-03-03T21:54:58Z
项目社区:https://github.com/byteboomers/vue-autofocus-directive

开源协议:MIT License

下载


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

  1. npm install --save vue-autofocus-directive

npm package link

Usage

  1. import Vue from "vue";
  2. import autofocus from "vue-autofocus-directive";
  3. Vue.directive("autofocus", autofocus);
  1. <input v-autofocus />

Options

binding

  • Type: value
  • Default: undefined
  • Description: Required when using dynamic value

Example

  1. <template>
  2. <form>
  3. <label>Email</label>
  4. <input
  5. v-autofocus
  6. v-model="email"
  7. type="email"
  8. name="email"
  9. placeholder="Email"
  10. />
  11. </form>
  12. </template>

or

  1. <template>
  2. <form>
  3. <label>Email</label>
  4. <input
  5. v-autofocus="dynamicValue"
  6. v-model="email"
  7. type="email"
  8. name="email"
  9. placeholder="Email"
  10. />
  11. </form>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. dynamicValue: false
  18. };
  19. }
  20. };
  21. </script>