Skip to content

BizButton 按钮 ​

常用的操作按钮,基于 el-button 二次封装:原生 props / 事件 / class 全量透传,并扩展 only-icon 图标按钮模式(隐藏文本、按钮方形化,鼠标移入以 tooltip 呈现按钮文本)与图标三通道接入(组件 / 第三方字体图标 class / 插槽)。

基础用法 ​

与 el-button 完全一致:type / size / plain / round / circle / text / link / loading / disabled / native-type 等属性与事件经 $attrs 透传,二次封装不截断原生能力。

icon 传组件(@element-plus/icons-vue);loading 时 loading 图标替换 icon,与 el-button 语义一致。

图标按钮模式(only-icon) ​

only-icon 隐藏按钮文本、按钮方形化(宽高一致:默认 32px / small 24px / large 40px,取 EP 组件尺寸变量),鼠标移入显示 tooltip——文本默认自动取按钮默认插槽文案,无需重复声明;tooltip prop 可覆盖,circle / text / link 形态不受方形化干预。

disabled 状态下原生 button 不触发 hover 事件,tooltip 不显示(el-button 原生行为,与 EP 官方一致)。

第三方字体图标(iconfont / RemixIcon / Font Awesome...) ​

icon 传 class 字符串 即接入任意字体图标库:el-button 原生 icon prop 内部按组件名解析字符串,无法承载字体 class,BizButton 对字符串自渲染 <i :class> 通道承载。字体图标 css 由业务应用自行引入(组件库不内置图标资源)。

demo 内用伪 iconfont class 模拟(离线可跑);真实项目引入 iconfont css 后原样传入 icon="iconfont icon-edit" 即可。

图标接入三通道 ​

通道传参形态适用
组件:icon="Edit"(Component)@element-plus/icons-vue 图标、业务自定义 SVG 组件
字体 classicon="iconfont icon-edit"(string)iconfont 字体模式、RemixIcon、Font Awesome 等一切 class 字体图标
插槽#iconiconfont symbol 模式(<svg><use href="#icon-xxx"/></svg>,非 class 驱动)、完全自定义图标结构
ts
// 1. 业务应用全局引入字体图标 css(一次性,与组件库无关)
import '@/assets/iconfont/iconfont.css'      // iconfont 项目下载到本地
import 'remixicon/fonts/remixicon.css'       // 或第三方库:npm i remixicon
vue
<!-- 2. class 原样传入即可 -->
<BizButton icon="iconfont icon-edit" only-icon>编辑</BizButton>
<BizButton icon="ri-delete-bin-line" only-icon type="danger">删除</BizButton>

<!-- symbol 模式走 #icon 插槽 -->
<BizButton only-icon>
  编辑
  <template #icon>
    <svg class="icon" aria-hidden="true"><use xlink:href="#icon-edit" /></svg>
  </template>
</BizButton>

表格行操作列(图标按钮组) ​

华东仓盘点单
9 月对账单
删除按钮点击后进入 loading(仅作演示,图标按钮同样支持)
操作列宽度敏感场景:查看 / 编辑 / 删除收敛为 3 个 only-icon 图标按钮(tooltip 补充语义),删除异步期间 loading 图标自动让位为转圈。

表单底部操作组 ​

表单提交场景:主操作 loading、次操作 plain、放弃编辑用 link 弱化——按钮层级即操作层级。

批量操作条 ​

已选 3 条
批量场景:已选计数 + 启用 / 停用 / 导出 / 删除四个动作——图标按钮与文字按钮混用,删除走 BizConfirmButton 二次确认。

按角色权限渲染 ​

权限场景:切换角色观察按钮三态——管理员全可见、运营部分禁用(disabled + 原因提示)、访客隐藏(v-if)。

Props ​

属性名类型默认值说明
iconComponent | string—图标:组件(EP 图标 / 自定义 SVG 组件)或字体图标 class 字符串,详见图标接入三通道
only-iconbooleanfalse图标按钮模式:隐藏文本、按钮方形化,hover 显示 tooltip(文本自动取默认插槽)
tooltipstring''tooltip 文本;留空自动取默认插槽文本;两者皆空 tooltip 自动禁用
tooltip-placement'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end''top'tooltip 弹出方位
tooltip-effect'dark' | 'light''dark'tooltip 主题
tooltip-disabledbooleanfalse关闭 tooltip
tooltip-show-afternumber0tooltip 显示延迟(ms)
tooltip-hide-afternumber0tooltip 隐藏延迟(ms)

除上述扩展属性外,其余属性全部透传至 el-button(type / size / plain / round / circle / text / link / loading / loading-icon / disabled / native-type / autofocus / tag...)。

Events ​

无自定义事件,el-button 原生事件经 $attrs 原样透传:

事件名参数说明
click(event: MouseEvent)点击时触发(透传 el-button)

Slots ​

插槽名说明
default按钮文本;only-icon 模式下作为 tooltip 文案来源(自动同步,插槽内容变化跟随)
icon自定义图标内容(iconfont symbol 模式 / 任意结构),优先级低于 icon prop

Expose ​

属性/方法说明
buttonRef内部 el-button 组件实例(EP 暴露 ref:原生 button 元素)
focus(): void 聚焦内部原生 button 元素
blur(): void 移除内部原生 button 元素的焦点