@aburai/vue-autofocus 中文文档教程

发布于 4年前 浏览 20 项目主页 更新于 3年前

vue-autofocus

UNDER CONSTRUCTION - use at own risc and create issues

Introduction

vue-autofocusVue.js 的插件。 功能包括:

  • many supported selectors to query control to focus
  • options for finetuning (see default global options)
  • option for debugging (logs focus workflow)

Install

来自 npm:

$ npm install @aburai/vue-autofocus --save
$ yarn add @aburai/vue-autofocus

Usage

append plugin to Vue

import Vue from 'vue'
import VueAutofocus from '@aburai/vue-autofocus'
Vue.use(VueAutofocus)
// OR
Vue.use(VueAutofocus, {globalOptions})

default global options

{
  initDelay: 300,
  focusDelay: 100,
  refocusDelay: 100,
  select: true,
  debug: false
}

use plugin

mounted() {
    this.$autofocus() // use this.$el to find a focusable control
    this.$autofocus('#my-element') // find element by id in this.$el
    this.$autofocus(this.$refs.form)
    this.$autofocus({ref: 'form'}) // get selector from this.$refs after $nextTick
    this.$autofocus(this.$refs.dialog, {initDelay: 600, debug: true})
    this.$autofocus(this.$refs.input, {select: false}) // do not select input text
}

Troubleshooting

的情况下关注观察者中的对话框元素

示例:在 ref错误

watch: {
  dialog(state) {
    // this.$refs.dialogcard could be undefined
    if (state) this.$autofocus(this.$refs.dialogcard)
  }
}

正确

watch: {
  dialog(state) {
    if (state) this.$nextTick(() => this.$autofocus(this.$refs.dialogcard))
    // OR
    if (state) this.$autofocus({ref: 'dialogcard'})
  }
}

License

MIT

版权所有 (c) 2019 年至今 André Bunse (aburai)

Special Thanks

vue-router 作为一个好的 vue 插件模板的样板

vue-autofocus

UNDER CONSTRUCTION - use at own risc and create issues

Introduction

vue-autofocus is a plugin for Vue.js. Features include:

  • many supported selectors to query control to focus
  • options for finetuning (see default global options)
  • option for debugging (logs focus workflow)

Install

From npm:

$ npm install @aburai/vue-autofocus --save
$ yarn add @aburai/vue-autofocus

Usage

append plugin to Vue

import Vue from 'vue'
import VueAutofocus from '@aburai/vue-autofocus'
Vue.use(VueAutofocus)
// OR
Vue.use(VueAutofocus, {globalOptions})

default global options

{
  initDelay: 300,
  focusDelay: 100,
  refocusDelay: 100,
  select: true,
  debug: false
}

use plugin

mounted() {
    this.$autofocus() // use this.$el to find a focusable control
    this.$autofocus('#my-element') // find element by id in this.$el
    this.$autofocus(this.$refs.form)
    this.$autofocus({ref: 'form'}) // get selector from this.$refs after $nextTick
    this.$autofocus(this.$refs.dialog, {initDelay: 600, debug: true})
    this.$autofocus(this.$refs.input, {select: false}) // do not select input text
}

Troubleshooting

example: focus on dialog element in a watcher with ref

wrong

watch: {
  dialog(state) {
    // this.$refs.dialogcard could be undefined
    if (state) this.$autofocus(this.$refs.dialogcard)
  }
}

correct

watch: {
  dialog(state) {
    if (state) this.$nextTick(() => this.$autofocus(this.$refs.dialogcard))
    // OR
    if (state) this.$autofocus({ref: 'dialogcard'})
  }
}

License

MIT

Copyright (c) 2019-present André Bunse (aburai)

Special Thanks

to vue-router as a boilerplate for a good vue plugin template

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文