• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >微信小程序 > 微信小程序实现分页下拉加载的实例代码

微信小程序实现分页下拉加载的实例代码

作者:匿名 字体:[增加 减小] 来源:互联网 时间:2018-11-30

匿名通过本文主要向大家介绍了小程序开发等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
转眼间我们教你微信小程序系列已经有十节系列课程了,每天的工作压力繁重,小女子也不知道自己还能坚持这样的系列教程多久。只希望每篇教程真的对大家有帮助。这节课我们要介绍的就是如何实现分页的下拉加载,我们先来看效果图

微信小程序实现分页下拉加载的实例代码

<view class="copyright">
    <view class="copyright_item">CopyRight:All Right Reserved</view>
    <view class="copyright_item">原创作者:51小程序</view>
    <view class="copyright_item">微信小程序开发者社区</view>
    <view class="copyright_item">HTML51.COM</view>
    <view class="copyright_item"><image class="img" src="../copyright/image/logo.png"/></view>
    <view class="goto_counter"><button type="default" bindtap="goto_counter">点击进入下拉加载演示页面</button></view>
</view>

<view class="search"> <view class="search-bar"> <view class="search-wrap"> <icon type="search" size="16" class="icon-search" /> <input type="text" placeholder="请输入搜索内容" class="search-input" name="searchKeyword" bindinput="bindKeywordInput" value="{{searchKeyword}}" /> </view> <view class="search-cancel" bindtap="keywordSearch">搜索</view> </view> <view class="search-result"> <scroll-view scroll-y="true" bindscrolltolower="searchScrollLower"> <view class="result-item" wx:for="{{searchSongList}}" wx:key="unique" data-data="{{item}}" > <view class="icon{{item.isonly=='0' ? ' nocopyright' : ''}}"></view> <text class="title">{{item.songname}}</text> <view class="subtitle"> <text wx:for="{{item.singer}}" wx:key="unique">{{item.name}}</text> </view> </view> <view class="loading" hidden="{{!searchLoading}}">正在载入更多...</view> <view class="loading complete" hidden="{{!searchLoadingComplete}}">已加载全部</view> </scroll-view> </view> </view>

2.index.wxss

page{ 
  display: flex;  
  flex-direction: column;  
  height: 100%;  
} 
   
/*搜索*/ 
.search{ 
  flex: auto;  
  display: flex;  
  flex-direction: column;  
  background: #fff;  
} 
.search-bar{ 
  flex: none;  
  display: flex;  
  align-items: center;  
  justify-content: space-between;  
  padding: 20rpx;  
  background: #f4f4f4;  
} 
.search-wrap{ 
  position: relative;  
  flex: auto;  
  display: flex;  
  align-items: center;  
  height: 80rpx;  
  padding: 0 20rpx;  
  background: #fff;  
  border-radius: 6rpx;  
} 
.search-wrap .icon-search{ 
  margin-right: 10rpx;  
} 
.search-wrap .search-input{ 
  flex: auto;  
  font-size: 28rpx;  
} 
.search-cancel{ 
  padding: 0 20rpx;  
  font-size: 28rpx;  
} 
   
/*搜索结果*/ 
.search-result{ 
  flex: auto;  
  position: relative;  
} 
.search-result scroll-view{ 
  position: absolute;  
  bottom: 0;  
  left: 0;  
  right: 0;  
  top: 0;  
} 
.result-item{ 
  position: relative;  
  display: flex;  
  flex-direction: column;  
  padding: 20rpx 0 20rpx 110rpx;  
  overflow: hidden;  
  border-bottom: 2rpx solid #e5e5e5;  
} 
   
.result-item .media{ 
  position: absolute;  
  left: 16rpx;  
  top: 16rpx;  
  width: 80rpx;  
  height: 80rpx;  
  border-radius: 999rpx;  
} 
.result-item .title, 
.result-item .subtitle{ 
  overflow: hidden;  
  text-overflow: ellipsis;  
  white-space: nowrap;  
  line-height: 36rpx;  
} 
.result-item .title{ 
  margin-bottom: 4rpx;  
  color: #000;  
} 
.result-item .subtitle{ 
  color: #808080;  
  font-size: 24rpx;  
} 
.result-item:first-child .subtitle text{ 
  margin-right: 20rpx;  
} 
.result-item:not(:first-child) .subtitle text:not(:first-child):before{ 
  content: '/';  
  margin: 0 8rpx;  
} 
.loading{ 
  padding: 10rpx;  
  text-align: center;  
} 
.loading:before{ 
  display: inline-block;  
  margin-right: 5rpx;  
  vertical-align: middle;  
  content: '';  
  width: 40rpx;  
  height: 40rpx;  
  background: url(../index/images/icon-loading.png) no-repeat;  
  background-size: contain;  
  animation: rotate 1s linear infinite;  
} 
.loading.complete:before{ 
  display: none;  
}

3.index.js

var util = require('../../utils/util.js') 
Page({ 
  data: { 
    searchKeyword: '',  //需要搜索的字符  
    searchSongList: [], //放置返回数据的数组  
    isFromSearch: true,   // 用于判断searchSongList数组是不是空数组,默认true,空的数组  
    searchPageNum: 1,   // 设置加载的第几次,默认是第一次  
    callbackcount: 15,      //返回数据的个数  
    searchLoading: false, //"上拉加载"的变量,默认false,隐藏  
    searchLoadingComplete: false  //“没有数据”的变量,默认false,隐藏  
  }, 
  //输入框事件,每输入一个字符,就会触发一次  
  bindKeywordInput: function(e){ 
    console.log("输入框事件") 
    this.setData({ 
      searchKeyword: e.detail.value 
    }) 
  }, 
  //搜索,访问网络  
  fetchSearchList: function(){ 
    let that = this;  
    let searchKeyword = that.data.searchKeyword,//输入框字符串作为参数  
        searchPageNum = that.data.searchPageNum,//把第几次加载次数作为参数  
        callbackcount =that.data.callbackcount; //返回数据的个数  
    //访问网络  
    util.getSearchMusic(searchKeyword, searchPageNum,callbackcount, functio



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

相关文章

  • 2018-11-30微信小程序商城开发之商城首页福利场不限下拉刷新动态API数据的代码实现
  • 2018-11-30小程序开发的图文详解
  • 2018-11-23微信小程序云开发 开发指引
  • 2018-11-30微信小程序中的onLoad的解析
  • 2018-11-30如何使用ActiveMQ测试小程序
  • 2018-11-30微信小程序如何使用webview调用微信扫一扫的功能
  • 2018-11-30谈谈多客服功能的现状与实例
  • 2018-11-30微信小程序中range-key多列选择器的使用示例
  • 2018-11-23微信小程序云开发服务端数据库API 统计集合记录数
  • 2018-11-30认清微信小程序开发+案例demo

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 如何获取小程序中的二维码(代码)
    • 微信小程序 网络请求(post请求,get请求)
    • 小程序之使用for循环绑定item的点击事件的实现
    • 微信小程序用PHP实现支付功能
    • 如何通过LayuiAdmin&LayIM&Thinkphp&Gateway实现小程序多客服接入系统的例子
    • 24小时开发阴阳师小程序
    • 微信小程序开发:在Gulp的基础上构建的工作流程
    • Angularjs过滤器完成排序功能实例详解
    • 微信小程序:文件管理 API说明
    • 微信小程序中生成图片的代码

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有