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官网

相关推荐
2501_9151063214 分钟前
“HTTPS Everywhere” 的工程化实践,从全面加密到排查与真机取证
网络协议·http·ios·小程序·https·uni-app·iphone
rookie_fly19 分钟前
基于Vue的数字输入框指令
前端·vue.js·设计模式
元直数字电路验证26 分钟前
ASP.NET Core Web APP(MVC)开发中无法全局配置 NuGet 包,该怎么解?
前端·javascript·ui·docker·asp.net·.net
rexling11 小时前
【Spring Boot】Spring Boot解决循环依赖
java·前端·spring boot
我有一棵树1 小时前
Vue 项目中全局样式的正确写法:不要把字体和主题写在 #app 上
前端·javascript·vue.js
韩立学长2 小时前
【开题答辩实录分享】以《足球社区微信小程序》为例进行答辩实录分享
微信小程序·小程序
龙仔CLL2 小时前
微前端乾坤vue3项目使用tinymce,通过npm,yarn,pnpm包安装成功,但是引用报错无法使用
javascript·arcgis·npm
Luna-player2 小时前
npm : 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本,解决方法
前端·npm·node.js
悢七2 小时前
windows npm打包无问题,但linux npm打包后部分样式缺失
linux·前端·npm
Felicity_Gao2 小时前
uni-app App升级功能实现
前端·学习·uni-app