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

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

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

首先,配置一下:show="isOpeneditem.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官网

相关推荐
随风一样自由8 小时前
【前端+跨端技术新格局】Tauri vs Electron 完整性能对比(2026实测数据+底层原理)
前端·javascript·electron
L-影8 小时前
Pydantic 模型:为你的 Web 数据装上“安检系统”
前端
Reload.8 小时前
GJ航司,验证码网易易盾 JS逆向 纯算轨迹
开发语言·前端·javascript
L-影8 小时前
FastAPI 请求头与 Cookie:Web 世界的“身份证”与“通行证”
前端·fastapi
IT_陈寒8 小时前
Vue的响应式更新把我坑惨了,原来是这个原因
前端·人工智能·后端
铁皮饭盒9 小时前
Bun.js 集成了 SQL/Redis/S3,为什么 Java/Go/Python 不集成?
javascript
年轻的砖头9 小时前
以Ajax方式提交整个表单
前端·javascript·ajax
L-影9 小时前
FastAPI CORS 跨域:Web 世界的“小区门禁”与“访客通行证”
前端·javascript·fastapi
stereohomology9 小时前
已进入初赛提交Demo的两个项目:(2)单独html钢琴
前端·html·why不coding
源图客9 小时前
Claude Code基础使用
服务器·前端·数据库