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

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

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

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

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

复制代码
<view class="uni-swipe-box" v-for=" (item,index) in userList" :key="index">
					<uni-swipe-action-item :threshold="0" :show="isOpened[item.id]" @change="change(index)"
						:auto-close='true' :right-options="options2" @click="bindClick($event,item)">
						<view class="content-box">
							<view class="user-name">姓名:<span class="span">{{item.userName}}</span></view>
							<view class="user-name">分组:<span class="span">{{item.groupName}}</span></view>
						</view>
					</uni-swipe-action-item>
				</view>

data() {
			return {	
				isOpened: {},
				tempOpened: null,  // 临时状态
      }
},

mounted() {
			// 初始化 userList 中每个item的 isOpened 状态
			this.userList.forEach(item => {
				this.$set(this.isOpened, item.id, false);
			});
		},
methods: {
			change(index) {
				// 使用tempOpened记录当前滑动状态,而不是直接改变isOpened
				this.tempOpened = !this.isOpened[this.userList[index].id];
			},

	bindClick(e, item) {
				const that = this
				console.log(e);
				console.log('item', item);
				const id = item.id
				if (e.content.text === '通过') {
					uni.showModal({
						title: '提交确认',
						content: `确认审核通过?`,
						success: (res) => {
							if (res.confirm) {
								that.isPass = true
								this.isOpened[item.id] = this.tempOpened; 
								that.tempOpened = null; // 清理临时状态
								that.makeRequst(id) // 调用后台接口
							} else if (res.cancel) {
								that.isPass = false
								that.isOpened[item.id] = that.tempOpened;
								that.tempOpened = null; // 清理临时状态
								console.log('用户取消操作');
							}
						}
					});
				} 
}

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

官方文档uni-app官网

相关推荐
旷世奇才李先生5 分钟前
Next.js 安装使用教程
开发语言·javascript·ecmascript
ᥬ 小月亮10 分钟前
webpack基础
前端·webpack
YongGit29 分钟前
探索 AI + MCP 渲染前端 UI
前端·后端·node.js
慧一居士1 小时前
<script setup>中的setup作用以及和不带的区别对比
前端
RainbowSea2 小时前
NVM 切换 Node 版本工具的超详细安装说明
java·前端
读书点滴2 小时前
笨方法学python -练习14
java·前端·python
Mintopia2 小时前
四叉树:二维空间的 “智能分区管理员”
前端·javascript·计算机图形学
慌糖2 小时前
RabbitMQ:消息队列的轻量级王者
开发语言·javascript·ecmascript
Mintopia2 小时前
Three.js 深度冲突:当像素在 Z 轴上玩起 "挤地铁" 游戏
前端·javascript·three.js
Penk是个码农2 小时前
web前端面试-- MVC、MVP、MVVM 架构模式对比
前端·面试·mvc