微信小程序(三十)界面交互-提示框注意事项

注释很详细,直接上代码

上一篇

新增内容:
1.showToastshowLoading的覆盖情况
2.覆盖情况导致的加载闪现情况的解决方法

源码:

index.wxml


<view class="students">
    <view class="item">
        <text>下标text>
        <text>序号text>
        <text>姓名text>
        <text>年龄text>
        <text>性别text>
    view>
    
    <view wx:for="{{students}}" wx:key="id" wx:for-item="stu" 
    wx:for-index="idx" class="item">
        <text>{{idx}}text>
        <text>{{stu.id}}text>
        <text>{{stu.name}}text>
        <text>{{stu.age}}text>
        <text>{{stu.gender}}text>
    view>
view>

<button type="primary" bind:tap="getMsgs" style="margin-top: 40rpx;">获取信息button>

index.wxss

.item{
    display: flex;
    /* 水平均分 */
    justify-content:space-evenly;
    height: 60rpx;
}

index.js

Page({
    data:{
        //存储学生信息的数组
        students:[]
    },
    getMsgs(){
        //显示加载框
        wx.showLoading({
          title: 'title',
          mask: true,//加上透明蒙版遮挡,防止在加载时用户继续点击触发事件 
          success: (res) => {},
          fail: (res) => {},
          complete: (res) => {},
        })

       wx.request({//自个在服务器写个php就行了

         url: 'http://xxxx.xxxxx.xxxx/xxxx/xxxx.php',
         data:{
             key:'xxxxxx'
         },

         success:(res) => {//成功的情况
           
             this.setData({//基础赋值,不明白的看上上上上……一篇

                students:res.data.msg//看清楚是冒号是冒号不是等号
             })

             //showToast和showLoading其实是同一个控件接口
             //如果成功则直接显示对话框,这样会自动覆盖之前的加载框
             wx.showToast({
                 icon:'none',//如果图标不是必要的加上这句,否则会限制显示字数
                 title: '加载成功'
             })

         },

         fail:(res)=>{//如果失败的话则不会覆盖,需要特判关闭一下
            wx.hideLoading({
              noConflict: true,
              success: (res) => {},
              fail: (res) => {},
              complete: (res) => {},
            })
         }
       })
   }
})

效果演示:

微信小程序(三十)界面交互-提示框注意事项_第1张图片

你可能感兴趣的:(微信小程序,微信小程序,小程序)