插件名称 | v-hotkey |
---|---|
发布时间 | 2020年9月6日 |
Vue 2.x指令–绑定组件的热键。
2020年9月3日
$ npm i --save v-hotkey
import Vue from 'vue'
import VueHotkey from 'v-hotkey'
Vue.use(VueHotkey)
<template>
<span v-hotkey="keymap" v-show="show">
按' ctrl + esc '切换我!按住“进入”把我藏起来!
</span>
</template>
<script>
export default {
data () {
return {
show: true
}
},
methods: {
toggle () {
this.show = !this.show
},
show () {
this.show = true
},
hide () {
this.show = false
}
},
computed: {
keymap () {
return {
// 'esc+ctrl' is OK.
'ctrl+esc': this.toggle,
'enter': {
keydown: this.hide,
keyup: this.show
}
}
}
}
}
</script>