在微信小程序中,可以使用 wx.showToast、wx.showLoading 和 wx.showModal 等方法来显示不同类型的提示框
-
wx.showToast:用于显示一条浮动的提示框,一般用于短暂的提示信息。
wx.showToast({
title: '提示内容',
icon: 'success', // 显示的图标,可选值:success/loading/none
duration: 2000, // 提示框持续时间,单位为毫秒
success: function () {
console.log('显示成功');
}
});
-
wx.showLoading:用于显示一个加载提示框,表示正在加载数据或执行操作。
wx.showLoading({
title: '加载中...',
mask: true, // 是否显示透明蒙层,防止触摸穿透,默认为 false
});
// 执行完异步操作后,隐藏加载提示框
wx.hideLoading();
-
wx.showModal:用于显示一个带有确定和取消按钮的模态对话框,用于用户确认或选择操作。
wx.showModal({
title: '提示',
content: '确定要删除吗?',
success: function (res) {
if (res.confirm) {
console.log('用户点击了确定');
} else if (res.cancel) {
console.log('用户点击了取消');
}
}
});
微信延迟执行下一步
// 执行当前步骤
// 停止 1 秒后,执行下一步操作
setTimeout(function () {
// 执行下一步操作
}, 1000);