当前位置: 首页 > news >正文

uni-app 之 下拉刷新,上拉加载,获取网络列表数据

uni-app 之 下拉刷新,上拉加载,获取网络列表数据

image.png

<template><view><!-- 车源模块 -->--- uni.request 网络请求API接口 ---<view v-for="(item) in newsArr" :key="item.id" style="display: flex; margin-top: 12rpx;"><!-- 免费的测试接口 --><image :src="item.picurl" mode="aspectFill" style="width: 300rpx;height: 200rpx;margin-left: 12rpx;"></image><view style="display: flex;flex-direction: column; flex-wrap: wrap;width: 400rpx; margin-left: 12rpx;"><text style=" font-weight:bold;"> {{item.title}}</text><text style="font-size:12rpx;">{{item.posttime}}</text><text style="color:#d81e06">{{item.hits}}</text></view></view><view v-if="!newsArr.length">没有数据的时候展示图片<image src="../../static/logo.png"></image></view></view>
</template><script>export default {data() {return {newsArr: [],currentPage: 1,}},onLoad() {this.getNewsData()},onPullDownRefresh() {console.log("111 111 下拉 " + this.currentPage)this.newsArr = [] // 下拉刷新时,清空集合this.currentPage = 1 // 下拉刷新时,page恢复初始1this.getNewsData() // 下拉刷新时,重新获取数据},onReachBottom() {console.log("111 111 到底啦 " + this.currentPage)uni.stopPullDownRefresh()this.currentPage++; // 上拉加载时,page+1this.getNewsData(50); // 传输的cid是在有头部tabbar点击切换的时候才用到,正常的列表可以删除},methods: {getNewsData(id = 50) {uni.request({url: "https://ku.qingnian8.com/dataApi/news/newslist.php",data: {// num:8,//展示几条,默认8条// cid:50,//列表分类:50国内,51国外,52体育,53软件,cid: id, // 传输的cid是在有头部tabbar点击切换的时候才用到,正常的列表可以删除page: this.currentPage},// timeout:"6000",success: res => {console.log(res) // log打印获取的数据// this.newsArr = res.datathis.newsArr = [...this.newsArr, ...res.data]uni.stopPullDownRefresh() // 加载出数据后关闭下拉动画},})}}}
</script><style></style>
// d81e06 紅
// f4ea2a 黃
// 1afa29 綠
// 1296db 藍
// 13227a 青
// d4237a 紫// ffffff 白
// 2c2c2c 黑

注意:pages.json里的enablePullDownRefresh要改为true

image.png

...

http://www.lryc.cn/news/169582.html

相关文章:

  • 笔记1.2 计算机网络结构
  • 使用Ansible Template模块进行配置文件管理
  • Secrets of RLHF in Large Language Models Part I: PPO
  • Java手写AVL树应用拓展案例
  • vue3+ts+uniapp小程序封装获取授权hook函数
  • 绘图(一)弹球小游戏
  • uniapp滑动事件
  • 入门人工智能 —— 学习 python 使用 IDE :vscode 完成编程 (2)
  • MyBatis字段名和属性名不一样的解决方案
  • Postman应用——Collection、Folder和Request
  • 驱动开发,stm32mp157a开发板的led灯控制实验
  • 黑客入侵机构,导致2万条信息被卖
  • 循环购:让消费者和商家共赢的新型电商模式
  • 分布式缓冲-Redis
  • C# 流Stream详解(3)——FileStream源码
  • C语言的文件操作(炒详解)
  • 27.基于ADS的不等分威尔金森功分器设计
  • Linux自用命令
  • clickhouse union all之后数据量不一致
  • 力扣刷题19-删除链表的倒数第N个节点
  • Unity中的简单数据存储办法
  • Pytorch-MLP-CIFAR10
  • SQL2 查询多列
  • 算法分享三个方面学习方法(做题经验,代码编写经验,比赛经验)
  • 爬虫 — 验证码反爬
  • 视频图像处理算法opencv模块硬件设计图像颜色识别模块
  • 目标检测网络之Fast-RCNN
  • Golang Gorm 创建HOOK
  • 计算机视觉的应用15-图片旋转验证码的角度计算模型的应用,解决旋转图片矫正问题
  • 【Seata】分布式事务问题和理论基础