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>
相关推荐
fakaifa4 分钟前
CRMEB多门店 v3.3源码 无授权限制+PC端+uniapp前端
小程序·uni-app·商城小程序·技术教程·源码下载·crmeb多门店
编程迪15 分钟前
小说阅读系统Java源码 小说阅读软件开发 小说app小程序
小程序·uni-app·小说源码·小说系统·小说阅读app
Q_Q5110082851 小时前
springboot+python+uniapp基于微信小程序的旅游服务系统景点信息展示 路线推荐 在线预约 评论互动系统
spring boot·python·微信小程序·django·flask·uni-app
你很易烊千玺2 小时前
uniapp多端打包样式处理
uni-app·多端化css处理
海绵宝宝不喜欢侬2 小时前
uniapp微信小程序保存海报到手机相册canvas
智能手机·微信小程序·uni-app·canva可画
海绵宝宝不喜欢侬3 小时前
【uniapp微信小程序】扫普通链接二维码打开小程序
微信小程序·小程序·uni-app
小蒜学长3 小时前
基于uni-app的蛋糕订购小程序的设计与实现(代码+数据库+LW)
java·数据库·spring boot·后端·小程序·uni-app
2501_915909067 小时前
HTTPS 错误解析,常见 HTTPS 抓包失败、443 端口错误与 iOS 抓包调试全攻略
android·网络协议·ios·小程序·https·uni-app·iphone
源码师傅11 小时前
uniapp开源多商户小程序商城平台源码 支持二次开发+永久免费升级
小程序·uni-app·多商户商城源码·uniapp开源商城源码·开源多商户小程序商城平台·商城小程序代码·多商户商城小程序源码
梦远青城12 小时前
C#地方门户网站 基于NET6.0、Admin.NET,uniapp,vue3,elementplus开源的地方门户网站项目
uni-app·开源·门户网站·地方生活网站·本地租房·本地找工作·东川本地生活