Skip to content

配置快捷键

运行环境: client
该文件中的代码将仅在浏览器中运行。导入包时请确保浏览器兼容性。

开始使用

创建 ./setup/shortcuts.ts,内容如下:

./setup/shortcuts.ts
ts
import type { NavOperations, ShortcutOptions } from '@slidev/types'
import { 
defineShortcutsSetup
} from '@slidev/types'
export default
defineShortcutsSetup
((
nav
: NavOperations,
base
: ShortcutOptions[]) => {
return [ ...
base
, // 保留现有快捷键
{
key
: 'enter',
fn
: () =>
nav
.
next
(),
autoRepeat
: true,
}, {
key
: 'backspace',
fn
: () =>
nav
.
prev
(),
autoRepeat
: true,
}, ] })

在 setup 函数中,你可以通过返回一个新的快捷键数组来自定义键盘快捷键。上面的示例将 next 操作绑定到 enter,将 prev 操作绑定到 backspace

请参阅导航操作章节了解默认快捷键和导航操作。

按键绑定格式

每个快捷键的 key 可以是字符串(例如 'Shift+Ctrl+A')或 Vue computed 形式的布尔值。请参阅 VueUse 的 useMagicKeys 了解更多信息。

Released under the MIT License.