Open wedjava opened 1 year ago
import hotkeys, { KeyHandler } from 'hotkeys-js'; import { onMounted, onUnmounted } from 'vue'; export const useHotKeys = (key: string, callback: KeyHandler, global = true): void => { onMounted(() => { hotkeys(key, callback); }); onUnmounted(() => { if (global) { hotkeys.unbind(key); } else { hotkeys.unbind(key, callback); } }); }; 这边使用的话 useHotKeys('ctrl+n, command+n', keyHandleCreate, false); useHotKeys('arrowup, arrowdown,ArrowDown,ArrowUp, ArrowRight', keyHandleUpdown, false); //不生效 控制台不打印
import hotkeys, { KeyHandler } from 'hotkeys-js'; import { onMounted, onUnmounted } from 'vue'; export const useHotKeys = (key: string, callback: KeyHandler, global = true): void => { onMounted(() => { hotkeys(key, callback); }); onUnmounted(() => { if (global) { hotkeys.unbind(key); } else { hotkeys.unbind(key, callback); } }); }; 这边使用的话 useHotKeys('ctrl+n, command+n', keyHandleCreate, false); useHotKeys('arrowup, arrowdown,ArrowDown,ArrowUp, ArrowRight', keyHandleUpdown, false); //不生效 控制台不打印