Nhảy tới nội dung

my.showToast

showToast

my.showToast là API để hiển thị Toast từ top và tự hide đi sau 1 khoảng thời gian được set hoặc dùng my.hideToast api.

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ệuMô tả
typestringsuccess hoặc fail
contentstringContent message của toast
buttonTextstringText của button, mặc định là rỗng
durationnumberThời gian để hide toast, mặc định là 3000ms
successFunctionCallback function khi hiển thị toast thành công.
failFunctionCallback function khi hiển thị toast 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">Toast API</view>
<view class="page-section">
<view class="page-section-title">my.showToast</view>
<view class="page-section-demo">
<button type="primary" onTap="onToast">Show Toast</button>
</view>
</view>
</view>
index.js
Page({
onToast() {
my.showToast({
type: "fail",
content: "Toast content",
buttonText: "OK",
duration: 3000,
success: () => {
my.alert({ title: "success" });
},
fail: (e) => {
my.alert({ title: `${e}` });
},
complete: () => {
console.log("Complete");
},
});
})