首页 > 小程序教程 > 微信小程序大图旅游文章支持无限加载列表样式制作设计教程

微信小程序大图旅游文章支持无限加载列表样式制作设计教程

上一篇 下一篇
本文给大家带来的是微信小程序大图旅游文章支持无限加载列表样式制作设计教程,制作好以后效果图如下:
一、wxml页面代码如下:
<import src="../../components/trip/trip.wxml"/>

<scroll-view class="list" style="height: {{ windowHeight }}px; width: {{ windowWidth }}px;" scroll-y="true"  bindscrolltolower="loadMore" lower-threshold="800">
  <block wx:for="{{ trips }}" wx:for-item="trip" wx:key="trip.data[0].id">
    <template is="m-trip" wx:if="{{ trip.type === 4 }}" data="{{trip: trip.data[0], mode: 1}}" />
  </block>
  <view class="loading">
    正在加载...
  </view>
</scroll-view>
 
二、wxss样式文件代码如下:
@import "../../components/trip/trip.wxss";

page{
  background-color: #f6f6f6;
}
.list{
}
.m-trip{
  margin: 20rpx;
}
.trip-title{
  margin-bottom: 10rpx;
}
.loading{
  color: #b0b0b0;
  text-align: center;
  margin: 20rpx 0;
}
.loading-gif{
  width: 220rpx;
  height: 42rpx;
  vertical-align: bottom;
}
三、js页面代码如下:
const App = getApp();
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');

const formatTime = util.formatTime;

Page({
  data: {
    trips: [],
    start: 0,
    loading: false,
    windowWidth: App.systemInfo.windowWidth,
    windowHeight: App.systemInfo.windowHeight,
  },
  onLoad() {
    this.loadMore();
  },
  onPullDownRefresh() {
    this.loadMore(null, true);
  },
  loadMore(e, needRefresh) {
    const self = this;
    const loading = self.data.loading;
    const data = {
      next_start: self.data.start,
    };
    if (loading) {
      return;
    }
    self.setData({
      loading: true,
    });
    api.getHotTripList({
      data,
      success: (res) => {
        let newList = res.data.data.elements;
        newList.map((trip) => {
          const item = trip;
          item.data[0].date_added = formatTime(new Date(item.data[0].date_added * 1000), 1);
          return item;
        });
        if (needRefresh) {
          wx.stopPullDownRefresh();
        } else {
          newList = self.data.trips.concat(newList);
        }
        self.setData({
          trips: newList,
        });
        const nextStart = res.data.data.next_start;
        self.setData({
          start: nextStart,
          loading: false,
        });
      },
    });
  },
  viewTrip(e) {
    const ds = e.currentTarget.dataset;
    wx.navigateTo({
      url: `../trip/trip?id=${ds.id}&name=${ds.name}`,
    });
  },
});

模板简介:该模板名称为【微信小程序大图旅游文章支持无限加载列表样式制作设计教程】,大小是,文档格式为.,推荐使用打开,作品中的图片,文字等数据均可修改,图片请在作品中选中图片替换即可,文字修改直接点击文字修改即可,您也可以新增或修改作品中的内容,该模板来自用户分享,如有侵权行为请联系网站客服处理。欢迎来懒人模板【小程序教程】栏目查找您需要的精美模板。

相关搜索
  • 下载密码 lanrenmb
  • 下载次数 25,084次
  • 使用软件
  • 文件格式
  • 文件大小
  • 上传时间 06-21
  • 作者 网友投稿
  • 肖像权 人物画像及字体仅供参考
栏目分类 更多 >
热门推荐 更多 >
单页式简历模板 企业网站 响应式 自适应 微信素材 微信公众平台 微信文章 微信模板 html5 微信图片
您可能会喜欢的其他模板