Button 按钮
按钮用于触发操作,支持图标、加载状态和多种视觉样式。
Usage 用法
ts
import { WButton } from '@wizdomt/ui'vue
<WButton label="确认" />使用前按快速开始安装插件与 CSS。组件保持 PrimeVue 4.5.5 原生 API。
Examples 示例
Basic 基础
通过 label 设置按钮文字,通过 click 监听用户操作。
vue
<script setup lang="ts">
import { ref } from 'vue'
import { WButton } from '@wizdomt/ui'
const count = ref(0)
</script>
<template>
<WButton label="提交" @click="count++" />
<span role="status">已点击 {{ count }} 次</span>
</template>Icons 图标
使用 icon 插槽传入图标。仅包含图标的按钮需要设置 aria-label。
vue
<script setup lang="ts">
import { WButton } from '@wizdomt/ui'
import { Add1Icon } from '@wizdomt/icons'
</script>
<template>
<WButton label="添加">
<template #icon><Add1Icon :size="18" /></template>
</WButton>
<WButton aria-label="添加项目" rounded outlined>
<template #icon><Add1Icon :size="18" /></template>
</WButton>
</template>Loading & Disabled 状态
loading 显示加载指示器;disabled 禁用按钮。
vue
<WButton label="提交中" loading />
<WButton label="禁用" disabled />Severity 语义
通过 severity 选择不同操作的视觉语义。默认使用 Figma 品牌蓝。
vue
<WButton label="primary" />
<WButton label="secondary" severity="secondary" />
<WButton label="success" severity="success" />
<WButton label="info" severity="info" />
<WButton label="warn" severity="warn" />
<WButton label="danger" severity="danger" />
<WButton label="contrast" severity="contrast" />Outlined 描边
vue
<WButton label="主要" outlined />
<WButton label="次要" severity="secondary" outlined />
<WButton label="危险" severity="danger" outlined />Text 文字
vue
<WButton label="主要" text />
<WButton label="次要" severity="secondary" text />
<WButton label="危险" severity="danger" text />Sizes 尺寸
vue
<WButton label="Small" size="small" />
<WButton label="Normal" />
<WButton label="Large" size="large" />API
| 名称 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| label | 按钮文字 | string | — |
| severity | 视觉语义 | string | primary |
| size | small / large;默认省略 | string | undefined |
| loading / disabled | 加载 / 禁用 | boolean | false |
| outlined / text / rounded | 描边 / 文字 / 圆角样式 | boolean | false |
事件:click,接收原生 MouseEvent。
插槽:default、icon、loadingicon。
完整 Props、事件、Slots、Methods 以上游锁定版本类型声明为准。PrimeVue v4 Button 文档可能包含较新 4.x API,使用时以本包 TypeScript 提示为准。
Accessibility 无障碍
组件保留原生按钮的键盘和焦点行为。使用 Tab 聚焦,通过 Enter 或空格触发操作。为图标按钮提供 aria-label,为操作提供清晰的文字标签。
布局由使用方控制,不自动切换交互。响应式指南说明不同设备的验证方法。