组件/CommandPalette 命令面板
通用组件

CommandPalette 命令面板

用于全局快捷指令/搜索的命令面板。

该页面由 AI 迁移生成,请谨慎使用

内容已迁移完成,但仍建议结合源码和人工评审结果使用。

CommandPalette 命令面板

用于全局快捷指令/搜索的命令面板。

基础用法

示例即将加载...
<script setup lang="ts">
import { ref } from 'vue'

const open = ref(false)
const selected = ref('')

const commands = [
  { id: 'open', title: 'Open File', description: 'Quickly open a file', shortcut: 'Cmd/Ctrl+O' },
  { id: 'search', title: 'Global Search', description: 'Search across content', shortcut: 'Cmd/Ctrl+K' },
  { id: 'settings', title: 'Settings', description: 'Open preferences', shortcut: 'Cmd/Ctrl+,' },
]

function onSelect(command: { title: string }) {
  selected.value = command.title
}
</script>

<template>
  <TxButton variant="primary" @click="open = true">
    Open command palette
  </TxButton>
  <TxCommandPalette v-model="open" :commands="commands" @select="onSelect" />
</template>

API

TxCommandPalette Props

属性名类型默认值说明
modelValueboolean-显示状态
commandsCommandPaletteItem[][]命令列表
placeholderstring'Search commands'搜索占位
emptyTextstring'No commands found'空提示
maxHeightnumber320列表最大高度
autoFocusbooleantrue自动聚焦
closeOnSelectbooleantrue选中后关闭

CommandPaletteItem

字段类型说明
idstring唯一标识
titlestring标题
descriptionstring描述
keywordsstring[]关键词
iconTxIconSource | string图标
shortcutstring快捷键
disabledboolean禁用

Events

事件名参数说明
update:modelValue(value)显示状态
select(item)选中命令
open-打开
close-关闭
update:query(value)搜索输入