微信小程序-scroll-view

scroll-view.wxml 文件

html 复制代码
<scroll-view 
  scroll-y 
  enable-back-to-top
  refresher-enabled
  class="scroll-y"
  lower-threshold="100"
  bindscrolltolower="getMoreHandler" 
  bindrefresherrefresh="refreshHandler"
  refresher-triggered="{{isTriggered}}">
  <view wx:for="{{ numList }}" wx:key="*this">{{ item }}</view>
</scroll-view>
  1. scroll-y : 上下滑动
  2. enable-back-to-top:点击状态栏回到顶部
  3. refresher-enabled:开启下拉刷新
  4. lower-threshold:距底部/右边多远时,触发 scrolltolower 事件
  5. bindscrolltolower:触发上滑加载事件
  6. refresher-triggered:设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发

scroll-view.wxss 文件

css 复制代码
.scroll-y{
  height: 100vh; 
  background-color: #efefef;
}

view{
  height: 500rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

view:nth-child(even){
  background-color: sienna;
}

view:nth-child(odd){
  background-color: slateblue;
}

scroll-view.js 文件

javascript 复制代码
Page({

  /**
   * 页面的初始数据
   */
  data: {
    numList: [1, 2, 3],
    isTriggered:false
  },

  getMoreHandler() {
    wx.showLoading({
      title: '加载中...',
    })
    setTimeout(() => {
      const n = this.data.numList[this.data.numList.length - 1]
      const newList = [n + 1, n + 2, n + 3]
      this.setData({
        numList: [...this.data.numList, ...newList]
      })
      wx.hideLoading()
    }, 1000);
  },
  refreshHandler() {
    wx.showToast({
      title: '下拉刷新',
    })
    this.setData({
      numList: [1, 2, 3],
      isTriggered:false
    })
  }
})

注意:

  1. 需要为scroll-view设置高度,否则不能滑动
  2. 如果在手机上预览出现不能上滑并且底部有空白,需要合理调整item和lower-threshold的高度
相关推荐
weixin_1772972206914 小时前
旧物二手回收小程序:引领绿色消费,开启时尚生活新方式
小程序·盲盒
2501_9160074715 小时前
Fastlane 结合 开心上架(Appuploader)命令行实现跨平台上传发布 iOS App 的完整方案
android·ios·小程序·https·uni-app·iphone·webview
韩立学长16 小时前
【开题答辩实录分享】以《植物病虫害在线答疑小程序的设计与实现》为例进行答辩实录分享
spring boot·小程序·vue
好想早点睡.17 小时前
vue2+UniApp微信小程序集成高德地图
微信小程序·小程序·uni-app
李慕婉学姐18 小时前
【开题答辩过程】以《基于微信小程序的线上讲座管理系统》为例,不会开题答辩的可以进来看看
javascript·mysql·微信小程序
2501_9159184119 小时前
iOS 上架应用市场全流程指南,App Store 审核机制、证书管理与跨平台免 Mac 上传发布方案(含开心上架实战)
android·macos·ios·小程序·uni-app·cocoa·iphone
Mr.Aholic20 小时前
分享几个开源的系统,包括小程序、商城系统、二手交易等常见的系统、很容易进行二次开发 【可以参考学习】
微信小程序·小程序·毕业设计·课程设计
2501_9159090621 小时前
HTTPS 错误排查实战,从握手到应用层的工程化流程
网络协议·http·ios·小程序·https·uni-app·iphone
JIngJaneIL1 天前
口腔健康系统|口腔医疗|基于java和小程序的口腔健康系统小程序设计与实现(源码+数据库+文档)
java·数据库·spring boot·小程序·论文·毕设·口腔医疗小程序
小光学长1 天前
基于微信小程序的背单词系统x1o5sz72(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·微信小程序·小程序