您的位置:首页 > 健康 > 美食 > uni-app uni-swipe-action 滑动操作状态恢复

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

2024/10/6 16:29:12 来源:https://blog.csdn.net/paradoxaaa_/article/details/139517418  浏览:    关键词: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记录当前滑动状态,而不是直接改变isOpenedthis.tempOpened = !this.isOpened[this.userList[index].id];},bindClick(e, item) {const that = thisconsole.log(e);console.log('item', item);const id = item.idif (e.content.text === '通过') {uni.showModal({title: '提交确认',content: `确认审核通过?`,success: (res) => {if (res.confirm) {that.isPass = truethis.isOpened[item.id] = this.tempOpened; that.tempOpened = null; // 清理临时状态that.makeRequst(id) // 调用后台接口} else if (res.cancel) {that.isPass = falsethat.isOpened[item.id] = that.tempOpened;that.tempOpened = null; // 清理临时状态console.log('用户取消操作');}}});} 
}

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

官方文档uni-app官网

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com