@4rk/vue-mousetrap 中文文档教程
@4rk/vue-mousetrap
一个 Vue 插件,它提供了一个指令,可以根据 Mousetrap 向您的组件添加全局键盘快捷键。
Installation
import VueMousetrap from "@4rk/vue-mousetrap";
Vue.use(VueMousetrap);
Usage
<template>
<div v-mousetrap="['mod+s']" @mousetrap="onMousetrap">
hit ctrl-s to save
</div>
</template>
<script>
export default {
methods: {
onMousetrap() {
console.log("save!");
}
}
};
</script>
API
v-mousetrap
指令需要 Mousetrap 兼容值,如 Mousetrap.bind 中所定义。
@mousetrap
事件与 Mousetrap 事件一起触发。
@4rk/vue-mousetrap
A Vue plugin providing a directive to add global keyboard shortcuts to your components based on Mousetrap.
Installation
import VueMousetrap from "@4rk/vue-mousetrap";
Vue.use(VueMousetrap);
Usage
<template>
<div v-mousetrap="['mod+s']" @mousetrap="onMousetrap">
hit ctrl-s to save
</div>
</template>
<script>
export default {
methods: {
onMousetrap() {
console.log("save!");
}
}
};
</script>
API
The v-mousetrap
directive expects a Moustrap compatible value as defined at Mousetrap.bind.
The @mousetrap
event triggers with the Mousetrap event.