跳至主要內容

交互

刘春龙原创...大约 3 分钟WEB前端小程序教程文档

消息提示框

showToast

<button type="primary" bindtap="clickToastHandle">弹出提示框</button>
属性类型默认值必填说明
titlestring提示的内容
iconstringsuccess图标
imagestring自定义图标的本地路径,image 的优先级高于 icon
durationnumber1500提示的延迟时间
maskbooleanfalse是否显示透明蒙层,防止触摸穿透

icon 详情

合法值说明
success显示成功图标,此时 title 文本最多显示 7 个汉字长度
error显示失败图标,此时 title 文本最多显示 7 个汉字长度
loading显示加载图标,此时 title 文本最多显示 7 个汉字长度
none不显示图标,此时 title 文本最多可显示两行
Page({
  onLoad(options) {},
  clickToastHandle() {
    wx.showToast({
      title: "等待数据加载",
      icon: "loading",
      duration: 2000,
      mask: true,
      image: "../../images/loading.png",
    });
  },
});

hideToast

隐藏消息提示框

Page({
  onLoad(options) {},
  clickToastHandle() {
    wx.showToast({
      title: "等待数据加载",
      icon: "loading",
      duration: 5000,
      mask: false,
      image: "../../images/loading.png",
    });
  },
  clickHideToast() {
    wx.hideToast();
  },
});












 


loading 提示框

显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框

Page({
  onLoad(options) {
    wx.showLoading({
      title: "加载中",
    });
  },
});
属性类型默认值必填说明
titlestring提示的内容
maskbooleanfalse是否显示透明蒙层,防止触摸穿透
Page({
  onLoad(options) {
    wx.showLoading({
      title: "加载中",
      mask: true,
    });

    setTimeout(() => {
      wx.hideLoading();
    }, 2000);
  },
});

模态对话框

显示模态对话框,其实就是可以进行交互了

基本对话框

<button type="primary" bindtap="clickModalHandle">显示对话框</button>
属性类型默认值必填说明
titlestring提示的标题
contentstring提示的内容
showCancelbooleantrue是否显示取消按钮
cancelTextstring取消取消按钮的文字,最多 4 个字符
cancelColorstring#000000取消按钮的文字颜色,必须是 16 进制格式的颜色字符串
confirmTextstring确定确认按钮的文字,最多 4 个字符
confirmColorstring#576B95确认按钮的文字颜色,必须是 16 进制格式的颜色字符串
editablebooleanfalse是否显示输入框
placeholderTextstring显示输入框时的提示文本

存在输入框的对话框

<button type="primary" bindtap="clickModalHandle">显示对话框</button>

操作菜单

显示操作菜单,菜单会从底部弹出

<button type="primary" bindtap="clickActionSheetHandle">显示底部菜单栏</button>
属性类型默认值必填说明
itemListArray.按钮的文字数组,数组长度最大为 6
itemColorstring#000000按钮的文字颜色
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
获取数据
Page({
  data: {
    citys: ["北京", "西安", "太原", "河北", "内蒙"],
  },
  clickActionSheetHandle() {
    var that = this;
    wx.showActionSheet({
      itemList: this.data.citys,
      itemColor: "#f00",
      success(res) {
        console.log(that.data.citys[res.tapIndex]);
      },
      fail(res) {
        console.log(res.errMsg);
      },
    });
  },
});
上次编辑于:
贡献者: 刘春龙
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.7