Skip to content

Fab 悬浮按钮

悬浮操作按钮(Floating Action Button)是一个特殊的圆形按钮,用于表示应用程序中最重要的操作。它通常固定在屏幕的某个位置,带有阴影和悬浮动画效果,类似于 Material Design 中的 FAB 组件。

基础用法

最基本的悬浮按钮形式,支持不同的颜色主题。

vue
<template>
  <u-fab>+</u-fab>
  <u-fab color="success">+</u-fab>
  <u-fab color="warning">+</u-fab>
  <u-fab color="error">+</u-fab>
  <u-fab color="info">+</u-fab>
</template>

不同尺寸

悬浮按钮支持四种不同的尺寸:small、medium、large,以及 extended 扩展样式。

vue
<template>
  <u-fab size="small">+</u-fab>
  <u-fab size="medium">+</u-fab>
  <u-fab size="large">+</u-fab>
</template>

扩展按钮

Extended FAB 支持显示文字,可以选择是否同时显示图标。

vue
<template>
  <u-fab size="extended" color="primary">
    <template #icon>+</template>
    新建
  </u-fab>
  
  <u-fab size="extended" color="success" label="创建"></u-fab>
  
  <u-fab size="extended" color="error">
    <template #icon>🗑</template>
    删除
  </u-fab>
</template>

按钮状态

悬浮按钮支持禁用、加载和无阴影状态。

vue
<template>
  <u-fab disabled color="primary">×</u-fab>
  <u-fab loading color="primary"></u-fab>
  <u-fab :shadow="false" color="primary">+</u-fab>
</template>

固定定位

通过 fixed 属性开启固定定位,并通过 top/right/bottom/left 调整位置。

vue
<template>
  <u-fab 
    fixed 
    bottom="24px" 
    right="24px" 
    color="primary"
  >
    +
  </u-fab>
</template>

API

属性说明类型默认值
color按钮颜色primary | success | warning | error | infoprimary
size按钮尺寸small | medium | large | extendedmedium
disabled是否禁用booleanfalse
loading是否加载中booleanfalse
fixed是否固定定位booleanfalse
top固定时的上边距string-
right固定时的右边距string-
bottom固定时的下边距string-
left固定时的左边距string-
shadow是否显示阴影booleantrue
ripple是否开启水波纹booleantrue
width自定义宽度string-
height自定义高度string-
label按钮标签文本string-

插槽

插槽名说明
default按钮内容
icon图标内容