小程序数据调用

布局

<view class="donate-statistics-box">
  <view class="donate-statistics-item">
    <view class="donate-statistics-project">总募集金额</view>
    <view class="donate-statistics-number-else">
      <span>¥</span>
      <span>{{total_donate}}</span>
    </view>
  </view>
  <view class="donate-statistics-line"></view>
  <view class="donate-statistics-item">
    <view class="donate-statistics-project">总帮助人群</view>
    <view class="donate-statistics-number">
      <span>{{total_help}}</span>
      <span>人</span>
    </view>
  </view>
  <view class="donate-statistics-line"></view>
  <view class="donate-statistics-item">
    <view class="donate-statistics-project">总公益人数</view>
    <view class="donate-statistics-number">
      <span>{{total_join}}</span>
      <span>人</span>
    </view>
  </view>
</view>

初始化数据

data: {
    total_donate:'0.00',
    total_help:0,
    total_join:0,
}

获取数据函数

// 获取统计数据
statData:function() {
    let that = this; // this指当前的Page对象
    util.getData('statData', {
      method: 'POST'
    }, function (data) {
      if (data.errno == 0) {
          that.setData({
            total_donate: data.data.total_donate,
            total_help: data.data.total_help,
            total_join: data.data.total_join,
          });
      }
    })
}

在onLoad中加载数据

/**
 * 生命周期函数--监听页面加载
 */
onLoad: function (options) {
    let that = this;
    this.statData();
}
posted @ 2019-03-30 10:45  TBHacker  阅读(621)  评论(0编辑  收藏  举报