uniapp列表滑动操作(删除、编辑)

本篇文章结合了下拉刷新、上拉加载,以及每一条列表的左滑删除,这里的header和footer盒子样式我就不写了,光写了main。是上中下布局,中间是内容,废话不说了,直接上代码!

html 复制代码
<template>
  <view class="wrap">
    <view class="header">
      ....
    </view>
    <view class="main">
      <scroll-view scroll-y class="scrollbox" @scrolltolower="lower" refresher-enabled="true"
        :refresher-triggered="trigger" @refresherrefresh="refresherrefresh" show-scrollbar="false">
        <uni-swipe-action>
          <uni-swipe-action-item
            v-for="(item, index) in 20"
            :right-options="options"
            @change="swipeChange($event, index)"
            @click="swipeClick($event, index)"
          >
          
            <text style="line-height: 40px;display: block;margin: 0 0 10px 0; background-color: aqua;">{{index}}</text>

          </uni-swipe-action-item>
        </uni-swipe-action>
        <!-- 加载更多 -->
        <view>
          <view class="loading-text" v-if="loadingFlag == 1">数据加载中...</view>
          <view class="loading-text" v-if="loadingFlag == 2">没有更多的数据...</view>
        </view>
      </scroll-view>
    </view>
    <view class="footer">
      ....
    </view>
  </view>
</template>

<script>
export default {
  data () {
    return {
      // 上拉刷新、下拉加载
      trigger: false,
      loadingFlag: 1,
      // 左滑删除
      options: [{
        text: '取消',
        style: {
          backgroundColor: '#007aff'
        }
      }, {
        text: '确认',
        style: {
          backgroundColor: '#dd524d'
        }
      }]
    }
  },
  methods: {
    // 上拉加载
    lower () {
      console.log('触底加载11')
    },
    // 下拉刷新
    refresherrefresh () {
      const _that = this
      this.trigger = true
      setTimeout(() => {
        _that.trigger = false
      }, 3000)
    },
    // 左滑删除
    swipeClick (e) {
      console.log('点击了' + (e.position === 'left' ? '左侧' : '右侧') + e.content.text + '按钮')
    },
    swipeChange (e, index) {
      console.log('当前状态:' + e + ',下标:' + index)
    }
  }
}
</script>

<style lang="scss" scoped>
.wrap {
  width: 100vw;
  height: 100vh;
  .header {
    // 这里的样式我就不写了
  }
  .main {
    width: 100%;
    height: calc(100vh - 50px - 50px);
    background-color: pink;
    overflow: auto;
    // 这个是scroll-view的盒子样式,必须要有,要不然不会触发 触底滚动事件
    .scrollbox {
      width: 100%;
      height: 100%;
    }
    // 加载更多
    .loading-text {
      font-size: $uni-size-loading-text;
      text-align: center;
      line-height: 30px;
      background-color: yellow;
    }
    // 左滑删除
    .uni-swipe {
      height: 40px !important;
      margin: 10px 0;
      .uni-swipe_box {
        height: 100%;
      }
    }
  }
  .main {
    // 这里的样式我就不写了
  }
}
</style>
相关推荐
棋子一名1 小时前
跑马灯组件 Vue2/Vue3/uni-app/微信小程序
微信小程序·小程序·uni-app·vue·js
游戏开发爱好者82 小时前
BShare HTTPS 集成与排查实战,从 SDK 接入到 iOS 真机调试(bshare https、签名、回调、抓包)
android·ios·小程序·https·uni-app·iphone·webview
2501_916008893 小时前
iOS 26 系统流畅度实战指南|流畅体验检测|滑动顺畅对比
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_915106325 小时前
苹果软件加固与 iOS App 混淆完整指南,IPA 文件加密、无源码混淆与代码保护实战
android·ios·小程序·https·uni-app·iphone·webview
2501_915921435 小时前
iOS 26 崩溃日志解析,新版系统下崩溃获取与诊断策略
android·ios·小程序·uni-app·cocoa·iphone·策略模式
2501_916013748 小时前
iOS 推送开发完整指南,APNs 配置、证书申请、远程推送实现与上架调试经验分享
android·ios·小程序·https·uni-app·iphone·webview
2501_9159090613 小时前
HTML5 与 HTTPS,页面能力、必要性、常见问题与实战排查
前端·ios·小程序·https·uni-app·iphone·html5
草字16 小时前
uniapp 防止长表单数据丢失方案,缓存表单填写内容,放置卡退或误操作返回。
前端·javascript·uni-app
2501_9151063217 小时前
JavaScript编程工具有哪些?老前端的实用工具清单与经验分享
开发语言·前端·javascript·ios·小程序·uni-app·iphone
2501_9160137419 小时前
iOS 上架 App 全流程实战,应用打包、ipa 上传、App Store 审核与工具组合最佳实践
android·ios·小程序·https·uni-app·iphone·webview