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

实现uniapp-微信小程序 搜索框+上拉加载+下拉刷新

 

pages.json 中的配置

   {

      "path": "pages/message",

      "style": {

        "navigationBarTitleText": "消息",

        "enablePullDownRefresh": true,

        "onReachBottomDistance": 50

      }

    },

<template><view class="message"><view class="box"><u-searchshape="square":show-action="false"placeholder="请输入标题"height="80"v-model="keyword"@change="keywordChange"></u-search></view><view class="list" v-if="list.length > 0"><view class="list_item" v-for="(item, index) in list" :key="index"><view class="left"><imagev-if="item.status === 1"class="message_icon"src="/static/message.png"></image><imagev-elseclass="message_icon"src="/static/message_icon.png"></image><view class="center"><label class="title">{{ item.title }}</label><label class="time">{{ item.createdAt }}</label></view></view><label @click="handleClick(item)">查看详情</label></view></view><view class="none" v-else><label>暂无消息~</label></view></view>
</template><script>
import { noticeSelect, noticeRead } from '@/api/tabBar.js'
export default {data () {return {isSending: false,keywordId: '',keyword: '',page: {currentPage: 1,pageSize: 20,total: 0},list: [],show: false,token: this.$store.state.user.token || ''}},onShow () {this.token = this.$store.state.user.tokenif (!this.token) {//#ifdef MP-WEIXINuni.reLaunch({url: '/pages/login/index'})//#endif//#ifdef H5|| APP-PLUSuni.navigateTo({url: '/pages/login/index'})//#endifsetTimeout(() => {uni.showToast({title: '请先登录',icon: 'error',duration: 1200})}, 600)return}this.init()},onHide () {this.token = ''this.resetVal()},computed: {// listComputed () {//   return this.list.filter(item => item.title.indexOf(this.keyword) > -1)// }},// 上拉触底时触发onReachBottom () {if (this.page.total === this.list.length) {return uni.showToast({title: '没有更多数据了...'})}if (this.isSending) returnthis.page.currentPage += 1this.init()},// 下拉刷新时触发onPullDownRefresh () {// 重置数据this.resetVal()// 重新请求this.init(true)},methods: {async handleClick (item) {await noticeRead(item.id)uni.setStorageSync('messageItem', JSON.stringify(item))uni.navigateTo({url: '/pages-other/MessageDetail'})},async init (bool) {this.isSending = trueconst res = await noticeSelect({...this.page,title: this.keyword})if (this.page.currentPage === 1) {this.list = res.data.returnNoticeList} else {this.list = [...this.list, ...res.data.returnNoticeList]}this.page.total = res.totalthis.isSending = falseif (bool) {uni.stopPullDownRefresh()}},keywordChange (e) {if (this.keywordId) clearTimeout(this.keywordId)this.keywordId = setTimeout(() => {this.page.currentPage = 1this.init()}, 600)},resetVal () {this.page.currentPage = 1this.page.total = 0this.list = []this.isSending = false}}
}
</script>

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

相关文章:

  • PostgreSQL 修改字段类型但是存在视图依赖
  • 基于.NET 9实现实时进度条功能:前后端完整示例教程
  • 力扣 LeetCode 19. 删除链表的倒数第N个结点(Day2:链表)
  • 音频格式转换
  • npm list @types/node 命令用于列出当前项目中 @types/node 包及其依赖关系
  • 【Spring】Spring框架中有有哪些常见的设计模式
  • 提升百度排名的有效策略与技巧解析
  • 【Linux】Linux下查看cpu信息指令(top/mpstat/iostat/pidstat)说明
  • HDLBIts习题(3):使用冒号表示位宽时,冒号两端必须是常量
  • C++20协程详解
  • Chromium 中chrome.system.display扩展接口定义c++
  • 容器docker的ulimit
  • 一、HTML
  • 使用Geekbench6软件对真实和虚拟的苹果桌面系统(macOS)进行打分比较
  • lua入门教程:随机数
  • 华为大咖说 | 浅谈智能运维技术
  • creo toolkit二次开发学习之获取任意选择模型作为元件,并进行获取约束等
  • sanitize-html 防止 XSS(跨站脚本攻击)
  • 【JavaEE】文件io
  • FlinkPipelineComposer 详解
  • 蓝桥杯-洛谷刷题-day2(C++)
  • 16008.行为树(五)-自定义数据指针在黑板中的传递
  • javascript Vue
  • 《揭秘观察者模式:作用与使用场景全解析》
  • 【QT常用技术讲解】优化网络链接不上导致qt、qml界面卡顿的问题
  • 下划线命名json数组转java对象
  • 实测运行容器化Nginx服务器
  • 显示器接口种类 | 附图片
  • C++初阶——list
  • 软件设计师-排序算法