Nhảy tới nội dung

my.showActionSheet

showActionSheet

my.showActionSheet là API để hiển thị bottom popup để user có thể chọn option.

Quét mã để trải nghiệm

Xem code mẫu trên Tini Studio

Demo

Trải nghiệm thử với trình giả lập bên dưới

API Params

Thuộc tínhKiểu dữ liệuBắt buộcMô tả
titlestringTitle của action sheet
itemsArray of stringsCác options hiển thị ra cho user
destructiveBtnIndexnumberChỉ ra index của option mà muốn hiển thị kiểu destructive
cancelButtonTextstringText của button cancel, mặc định là Cancel
successFunctionCallback function khi hiển thị bottom popup thành công.
failFunctionCallback function khi hiển thị bottom popup thất bại.
completeFunctionCallback function khi hoàn tất gọi hàm bất kể thành công hay thất bại.

Sample Code

index.txml
<view class="page">
<view class="page-description">Confirm API</view>
<view class="page-section">
<view class="page-section-title">my.confirm</view>
<view class="page-section-demo">
<button type="primary" onTap="onActionSheet">Show action sheet</button>
</view>
</view>
</view>
index.js
Page({
onActionSheet() {
my.showActionSheet({
title: 'Action Sheet',
items: ['Button 1', 'Button 2', 'Button 3'],
destructiveBtnIndex: 2,
success: (res) => {
const btn =
res.index === -1 ? 'Cancel' : 'at index ' + res.index;
my.alert({
title: `Clicked button ${btn}`
});
}
});
}
});