当前位置:   article > 正文

uni-app uni-swipe-action 滑动操作状态恢复

uni-app uni-swipe-action 滑动操作状态恢复

按照uni-app官方文档的写法 当前一条滑动确认之后 页面列表刷新 但是滑动的状态还在 入下图所示:

我们需要在滑动确认之后 页面刷新 滑动状态恢复 那么我们就来写一下这部分的逻辑:

首先,配置一下:show="isOpened[item.id]" @change="change(index)"

注意:isOpened一定要定位到你当前点击的内容,我这里是用id区分的, 不然会出现所有列表都同步滑开或者关闭

  1. <view class="uni-swipe-box" v-for=" (item,index) in userList" :key="index">
  2. <uni-swipe-action-item :threshold="0" :show="isOpened[item.id]" @change="change(index)"
  3. :auto-close='true' :right-options="options2" @click="bindClick($event,item)">
  4. <view class="content-box">
  5. <view class="user-name">姓名:<span class="span">{{item.userName}}</span></view>
  6. <view class="user-name">分组:<span class="span">{{item.groupName}}</span></view>
  7. </view>
  8. </uni-swipe-action-item>
  9. </view>
  1. data() {
  2. return {
  3. isOpened: {},
  4. tempOpened: null, // 临时状态
  5. }
  6. },
  7. mounted() {
  8. // 初始化 userList 中每个item的 isOpened 状态
  9. this.userList.forEach(item => {
  10. this.$set(this.isOpened, item.id, false);
  11. });
  12. },
  13. methods: {
  14. change(index) {
  15. // 使用tempOpened记录当前滑动状态,而不是直接改变isOpened
  16. this.tempOpened = !this.isOpened[this.userList[index].id];
  17. },
  18. bindClick(e, item) {
  19. const that = this
  20. console.log(e);
  21. console.log('item', item);
  22. const id = item.id
  23. if (e.content.text === '通过') {
  24. uni.showModal({
  25. title: '提交确认',
  26. content: `确认审核通过?`,
  27. success: (res) => {
  28. if (res.confirm) {
  29. that.isPass = true
  30. this.isOpened[item.id] = this.tempOpened;
  31. that.tempOpened = null; // 清理临时状态
  32. that.makeRequst(id) // 调用后台接口
  33. } else if (res.cancel) {
  34. that.isPass = false
  35. that.isOpened[item.id] = that.tempOpened;
  36. that.tempOpened = null; // 清理临时状态
  37. console.log('用户取消操作');
  38. }
  39. }
  40. });
  41. }
  42. }

这样就可以实现及时恢复滑动状态 

官方文档uni-app官网

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/719694
推荐阅读
相关标签
  

闽ICP备14008679号