pumpkin-ui
指南
组件
指南
组件
  • 基础组件

    • Button 按钮
    • Cell 单元格
    • Icon 图标
    • Popup 弹出层
    • Toast 轻提示
  • 表单组件

    • PickerView 选择器视图
    • Picker 选择器
    • DatePicker 日期时间选择器
    • Switch 开关
    • Field 输入项
    • Form 表单
    • Checkbox 复选框
    • Radio 单选框
  • 反馈组件

    • Overlay 遮罩
    • Loading 加载
    • ActionSheet 动作面板
    • Notify 消息提示
    • Skeleton 骨架屏
    • Dialog 对话框
  • 展示组件

    • Progress 进度条
    • Divider 分割线
    • Badge 徽标
    • Empty 空元素
    • Tag 标签

ActionSheet 动作面板

基本使用

命令式调用

script
import { ActionSheet } from "@pumpkin-ui/mobile"

ActionSheet.showActionSheet([
    {
        name:'选项一'
    },
    {
        name:'选项二'
    }
])

代码示例

基础用法

通过showActionSheet函数调用,第一个传入需要展示的选项即可。第一个参数也支持传入对象,对象中可以传入title、cancelText、overlay等属性。

template
 <div class="action-sheet-container">
    <pk-cell-group>
        <pk-cell is-link @click="showDefaultActionSheet">
            <template #title>基础用法</template>
        </pk-cell>
    </pk-cell-group>
</div>
script
import { ActionSheet, PkCellGroup, PkCell, Toast } from "@pumpkin-ui/mobile"

const showDefaultActionSheet = () => {
    ActionSheet.showActionSheet([
        {
            name: '选项1'
        }, {
            name: '选项2'
        }, {
            name: '选项3'
        }
    ]).then((res) => {
        if (res.type === 'confirm') {
            Toast.show(res.item.name)
        }
    })
}

style
.action-sheet-container {
    padding: 10px 0;
}

显示标题

通过showActionSheet第一个参数中的title属性可控制显示标题和子标题。

template
 <div class="action-sheet-container">
    <pk-cell-group>
        <pk-cell is-link @click="showTitleActionSheet">
            <template #title>显示标题</template>
        </pk-cell>
    </pk-cell-group>
</div>
script
import { ActionSheet, PkCellGroup, PkCell, Toast } from "@pumpkin-ui/mobile"

const showTitleActionSheet = () => {
    ActionSheet.showActionSheet({
        title: '测试',
        subTitle: '测试',
        actions: [
            {
                name: '123'
            }
        ]
    }).then((res) => {
        if (res.type === 'confirm') {
            Toast.show(res.item.name)
        } else if (res.type === 'cancel') {
            Toast.show('取消')
        }
    })
}

style
.action-sheet-container {
    padding: 10px 0;
}

隐藏取消按钮

通过设置showActionSheet第一个参数中的cancel属性为false可隐藏关闭按钮。

template
 <div class="action-sheet-container">
    <pk-cell-group>
        <pk-cell is-link @click="showNoCancelActionSheet">
            <template #title>隐藏取消按钮</template>
        </pk-cell>
    </pk-cell-group>
</div>
script
import { ActionSheet, PkCellGroup, PkCell, Toast } from "@pumpkin-ui/mobile"

const showNoCancelActionSheet = () => {
    ActionSheet.showActionSheet({
        actions: [
            {
                name: '123'
            },
            {
                name: '123456'
            }
        ],
        cancel:false
    }).then((res) => {
        if (res.type === 'confirm') {
            Toast.show(res.item.name)
        }
    })
}

style
.action-sheet-container {
    padding: 10px 0;
}

选项状态和颜色

通过设置actions中的disable和loading属性可修改选项的状态,设置color属性可以修改对应选项的颜色(此属性对loading和disable的选项无效)。

template
 <div class="action-sheet-container">
    <pk-cell-group>
        <pk-cell is-link @click="showStatusActionSheet">
            <template #title>选项状态和颜色</template>
        </pk-cell>
    </pk-cell-group>
</div>
script
import { ActionSheet, PkCellGroup, PkCell, Toast } from "@pumpkin-ui/mobile"

const showStatusActionSheet = () => {
    ActionSheet.showActionSheet([
        {
            name: '选项1',
            loading: true
        }, {
            name: '选项2',
            disabled: true
        }, {
            name: '选项3'
        }, {
            name: '选项321',
            color:'red'
        }
    ]).then((res) => {
        if (res.type === 'confirm') {
            Toast.show(res.item.name)
        }
    })
}

style
.action-sheet-container {
    padding: 10px 0;
}

API

命令式调用

方法

方法说明类型
ActionSheet.showActionSheet显示ActionSheet(option: ActionSheetOptions | ActionSheetItem[])=>Promise<ActionSheetCallbackParams>

ActionSheetOptions

属性名说明类型默认值
actions选项ActionSheetItem[][]
cancel显示取消booleantrue
cancelText取消文字string取消
title标题string``
subTitle子标题string``
overlay显示遮罩层booleantrue
overlayBackgroundColor遮罩层背景颜色string``
closeOnPressOverlay点击遮罩层关闭booleantrue
closeOnClickAction点击选项关闭booleantrue
onClose关闭时的回调()=>void
onClosed关闭动画结束时的回调()=>void
onOpen打开时的回调()=>void
onOpened打开动画结束时的回调()=>void
onCancel点击取消时的回调()=>void
onItemClick点击选项时的回调(item:ActionSheetItem,index:number)=>void

ActionSheetItem

属性名说明类型默认值可选
name名称string必选
color颜色string可选
loading加载状态boolean可选
disabled禁用状态boolean可选

ActionSheetCallbackParams

属性名说明类型默认值
type类型'confirm'|'cancel'
item选项(confirm时才有)ActionSheetItem
index索引(confirm时才有)number

Props

属性名说明类型默认值可选值
v-model是否显示动作面板组件,双向绑定boolean
actions选项ActionSheetItem[][]
cancel显示取消booleantrue
cancel-text取消文字string取消
title标题string``
sub-title子标题string``
overlay显示遮罩层booleantrue
overlay-background-color遮罩层背景颜色string``
close-on-press-overlay点击遮罩层关闭booleantrue
close-on-click-action点击选项关闭booleantrue

Events

事件名说明回调参数
onOpen打开时触发() => void
onClose打开时触发() => void
onOpened打开动画结束时触发() => void
onClosed关闭动画结束时触发() => void
onCancel点击取消时的回调()=>void
onItemClick点击选项时的回调(item:ActionSheetItem,index:number)=>void

Slot

插槽名说明

Exposes

名称说明类型说明
updateShow更新动作面板显示(show:boolean = true)=>void

样式变量

名称默认值说明
--pk-action-sheet-colorvar(--pk-text-color)
--pk-action-sheet-footer-gap8px
--pk-action-sheet-item-padding16px
--pk-action-sheet-item-icon24px
--pk-action-sheet-disabled-text-colorvar(--pk-text-color-disabled)
Last Updated:
Contributors: yranky
Prev
Loading 加载
Next
Notify 消息提示