swan.showModal

    Object object

    success返回参数说明

    扫码体验

    请使用百度APP扫码

    1. primary() {
    2. swan.showModal({
    3. title: '提示标题',
    4. content: '提示内容、告知状态、信息和解决方法,描述尽量控制在两行内',
    5. showCancel: true,
    6. cancelText: '辅助操作',
    7. confirmText: '主要操作'
    8. });
    9. }
    10. });

    代码示例2 - 无标题、单操作:

    1. <view class="card-area">
    2. <view class="top-description border-bottom">设置无标题,单操作按钮</view>
    3. <button bindtap="showModalNotitle" type="primary" hover-stop-propagation="true">无标题模态弹窗</button>
    4. </view>

    代码示例3 - 自定义选项颜色:

    1. <view class="card-area">
    2. <view class="top-description border-bottom">
    3. <view>自定义选项颜色</view>
    4. <view>
    5. confirmColor=“#000000”
    6. cancelColor=“#999999”
    7. </view>
    8. </view>
    9. <button bindtap="showModalColor" type="primary" hover-stop-propagation="true">自定义选项颜色的模态弹窗</button>
    10. </view>
    1. Page({
    2. showModalColor() {
    3. swan.showModal({
    4. content: '提示内容、告知状态、信息和解决方法,描述尽量控制在两行内',
    5. showCancel: true,
    6. confirmText: '操作',
    7. cancelText: '警示操作',
    8. cancelColor: '#FF0000'
    9. });
    10. }
    11. });

    参考示例2 - 开发者可自定义一个showModal

    1. <view class="wrap">
    2. <!--mask-->
    3. <view class="mask" bindtap="showModal" data-statu="close" s-if="{{showModalStatus}}"></view>
    4. <!--content-->
    5. <view animation="{{animationData}}" class="showModal-box" s-if="{{showModalStatus}}">
    6. <view class="showModal-title">标题</view>
    7. <view class="showModal-content">
    8. <view class="border-bottom">可自定义展示接口请求返回的数据</view>
    9. <view s-for="item, index in data" class="border-bottom">
    10. <view>{{index}}</view>
    11. <view>价钱:{{item.money}}</view>
    12. <view>途径:{{item.source}}</view>
    13. <view>类型:{{item.type}}</view>
    14. <view>满减活动:{{item.upTo}}</view>
    15. </view>
    16. </view>
    17. <view class="confirm" bindtap="showModal" data-statu="close">确定</view>
    18. </view>
    19. </view>
    1. Page({
    2. data: {
    3. showModalStatus: false,
    4. data: {}
    5. },
    6. showModal(e) {
    7. var currentStatu = e.currentTarget.dataset.statu;
    8. this.animation(currentStatu);
    9. this.request();
    10. },
    11. animation(currentStatu){
    12. var animation = swan.createAnimation({
    13. duration: 1000,
    14. timingFunction: "ease",
    15. });
    16. animation.opacity(0).rotateX(-100).step();
    17. this.setData({
    18. animationData: animation.export()
    19. setTimeout(function () {
    20. animation.opacity(1).rotateX(0).step();
    21. this.setData({
    22. animationData: animation
    23. })
    24. if (currentStatu == "close") {
    25. this.setData({showModalStatus: false});
    26. }
    27. }.bind(this), 200)
    28. if (currentStatu == "open") {
    29. this.setData({showModalStatus: true});
    30. }
    31. },
    32. request() {
    33. swan.request({
    34. url: 'https://sfc.baidu.com/shopping/nianhuo/bimai',
    35. header: {
    36. 'content-type': 'application/json'
    37. },
    38. method: 'POST',
    39. dataType: 'json',
    40. responseType: 'text',
    41. data: {
    42. key: 'value'
    43. },
    44. success: res => {
    45. this.setData({
    46. data: res.data.data.couponList
    47. })
    48. },
    49. fail: err => {
    50. console.log('错误码:' + err.errCode);
    51. console.log('错误信息:' + err.errMsg);
    52. }
    53. });
    54. }
    55. })

    Android