Skip to content

BottomSheet 底部弹窗

介绍

底部弹起的模态面板,可通过顶部把手拖拽调整高度,适用于展示列表、表单等自定义内容。

导入

js
import BottomSheet from '@/components/dialog/BottomSheet.vue'

用法

基础用法

最简单的 BottomSheet 用法,设置 show 控制显示,通过 #content 插槽传入内容,插槽会注入 close 方法用于关闭面板。

vue
<template>
  <BottomSheet
    :show="show1"
    :height="320"
    closeable
    @close="show1 = false"
  >
    <template #content="{ close }">
      <FlexCol :padding="24">
        <view style="font-size: 36rpx; font-weight: 600; margin-bottom: 24rpx;">基础用法</view>
        <view style="color: #666; margin-bottom: 32rpx;">底部弹起的模态面板,可通过顶部把手拖拽调整高度。</view>
        <view style="padding: 24rpx; background: #f5f5f5; border-radius: 12rpx; margin-bottom: 32rpx;">
          内容区域可放置列表、表单等任意内容。
        </view>
        <Button text="关闭" type="primary" size="large" @click="close" />
      </FlexCol>
    </template>
  </BottomSheet>
</template>

禁用拖拽

设置 enable-dragfalse 可隐藏顶部把手并禁用拖拽。

vue
<template>
  <BottomSheet
    :show="show2"
    :height="280"
    :enable-drag="false"
    closeable
    @close="show2 = false"
  >
    <template #content="{ close }">
      <FlexCol :padding="24">
        <view style="font-size: 36rpx; font-weight: 600; margin-bottom: 24rpx;">禁用拖拽</view>
        <view style="color: #666; margin-bottom: 32rpx;">设置 enableDrag 为 false 可隐藏顶部把手并禁用拖拽。</view>
        <Button text="关闭" type="primary" size="large" @click="close" />
      </FlexCol>
    </template>
  </BottomSheet>
</template>

吸附高度

通过 drag-snap-heights 设置松手后吸附的高度档位(单位 px),拖拽结束时会自动吸附到最近的一档。

vue
<template>
  <BottomSheet
    :show="show3"
    :height="300"
    :drag-snap-heights="[200, 400, 600]"
    closeable
    @close="show3 = false"
  >
    <template #content="{ close }">
      <FlexCol :padding="24">
        <view style="font-size: 36rpx; font-weight: 600; margin-bottom: 24rpx;">吸附高度</view>
        <view style="color: #666; margin-bottom: 32rpx;">通过 dragSnapHeights 设置松手后吸附的高度档位(如 200、400、600px)。</view>
        <Button text="关闭" type="primary" size="large" @click="close" />
      </FlexCol>
    </template>
  </BottomSheet>
</template>

自定义面板

使用 #content 插槽可完全自定义面板内容,例如配合 Cell、CellGroup 等组件。

vue
<template>
  <BottomSheet
    :show="show4"
    :height="450"
    closeable
    @close="show4 = false"
  >
    <template #content="{ close }">
      <FlexCol :padding="24">
        <view style="font-size: 36rpx; font-weight: 600; margin-bottom: 24rpx;">自定义面板</view>
        <view style="color: #666; margin-bottom: 24rpx;">可使用默认插槽 #content 完全自定义内容布局。</view>
        <CellGroup round>
          <Cell title="选项 A" showArrow touchable />
          <Cell title="选项 B" showArrow touchable />
          <Cell title="选项 C" showArrow touchable />
        </CellGroup>
        <Button text="关闭" type="primary" size="large" @click="close" />
      </FlexCol>
    </template>
  </BottomSheet>
</template>

API 参考

BottomSheet

底部弹窗组件,基于 Popup 实现,固定从底部弹出并支持拖拽调节高度。

Props

名称说明类型必填默认值
show是否显示booleanfalse
height初始高度(px)number-300
enableDrag是否启用拖拽(显示顶部把手)boolean-true
dragSnapHeights拖拽松手后吸附的高度档位(px 数组)number[]--
dragMinHeight拖拽时最小高度(px)number-100
dragMaxHeight拖拽时最大高度(px)number-1000
dragHandleColor顶部把手颜色string-'grey'
dragHandleSize顶部把手尺寸(rpx/px)number-200
innerStyle面板内容区域自定义样式ViewStyle--
closeable是否显示关闭按钮且点击遮罩可关闭boolean--
closeIcon关闭图标,设为 false 不显示string | false-'close'
closeIconSize关闭图标大小number-40
closeIconPosition关闭按钮位置PopupCloseButtonPosition-'right'
mask是否显示遮罩boolean-true
maskColor遮罩颜色string-'background.mask'
duration动画时长(ms)number-230
zIndex层级number-0
backgroundColor弹出层背景色string-'white'
safeArea是否考虑安全区boolean-true
margin对话框偏移边距number[]-[0,0,0,0]
inset整体边距(含遮罩)(number | string | undefined)[]--

说明:除上表外,BottomSheet 继承 Popup 的其余属性(如 round 已固定为 trueposition 固定为 bottomsize 由内部高度控制)。

Slots

名称说明
content自定义面板内容,作用域参数:{ close }close 用于关闭面板

Events

名称说明参数
close关闭时触发$event

方法(通过 ref 调用)

方法名说明参数 / 返回值
setDragHeight设置当前拖拽高度(height: number) => void
getDragHeight获取当前拖拽高度() => number
setDragHeightToMax将高度设为最大() => void
setDragHeightToMin将高度设为最小() => void

主题变量

名称类型默认值说明
BottomSheetHeightnumber300默认高度(px)
BottomSheetDragHandleColorstring'grey'拖拽把手颜色
BottomSheetDragHandleSizenumber200拖拽把手尺寸
BottomSheetDragMaxHeightnumber1000拖拽最大高度(px)
BottomSheetDragMinHeightnumber100拖拽最小高度(px)
BottomSheetCenterWidthstring'600rpx'居中宽度(由 Popup 继承)
BottomSheetBorderRadiusnumber/string10面板圆角
BottomSheetBackgroundColorstring'white'面板背景色
BottomSheetDragHandleBorderRadiusnumber/string10把手圆角
BottomSheetDragHandleMarginVerticalnumber/string25把手上下边距