解决a:if加载时候闪烁

axml


  msg1
  msg2

js

Page({
  data:{
    isShow:false,
    isMsg:1
  },
  getMsg() {
    my.request({
      url: app.globalData.host + 'api接口',
      method: 'POST',
      headers: {
        'content-type': 'application/json',
        'token': app.access_token
      },
      success: (res) => {
        if (res.data.status == 0) {
          this.setData({
            isCode:true
          })
        } 
        if (res.data.status == 1) {
          this.setData({
            isMsg: 0,
            isCode:true
          })
        }
      },
      fail: function (res) {
        console.log(res);
      },
      complete: function (res) {
        my.hideLoading();
      }
    });
  },
})

请求接口时闪烁,先把需要a:if的上一级元素的isShow设为false不显示,当接口数据加载完毕后判断走a:if还是a:else,然后把isShow设为true显示页面,页面不闪烁

你可能感兴趣的:(解决a:if加载时候闪烁)