微信小程序常用的3种提示弹窗

时间:2024-01-25 11:26:50

1. 表示操作成功,文字上方会显示一个表示操作成功的图标。

wx.showToast({
    title: \'操作成功!\',  // 标题
    icon: \'success\',   // 图标类型,默认success
    duration: 1500   // 提示窗停留时间,默认1500ms
})

 

2.表示加载中,显示为加载中图标。

wx.showToast({
    title: \'加载中...\',
    icon: \'loading\',
    duration: 1500
})

 

3.不显示图标,一般用作提示。

wx.showToast({
    title: \'该功能未上线!\',
    icon: \'none\',
    duration: 1500
})

 

以上3种弹窗均使用wx.showToast接口,调用后会根据设定的duration停留一定时间。

 

此外,表示加载中的弹窗还可以使用wx.showLoading接口,但调用该接口时弹窗并不会自动消失,而是需要手动调用wx.hideLoading接口使弹窗消失。

// 开始加载数据
wx.showLoading({
  title: \'加载中\',
})

// 数据加载中...
// 数据加载中...
// 数据加载完成,隐藏弹窗 wx.hideLoading()

 

 

完。