当前位置: 首页 > news >正文

微信小程序删除滑块 SwiperCell 自动收起 Van weapp van-swipe-cell 滑块自动收起 点击页面也自动收起滑块

  1. 在当前页面整个 view 中 给页面绑定 点击事件bindtap="onSwipeCellPage"
  2. 给 van-swipe-cell 组件设置 id (for循环可以添加 id="swip-cell-{{item.id}}"
  3. van-swipe-cell 组件 添加属性 当用户打开滑块时触发 bind:open="swiperCellOpen"
  4. van-swipe-cell 组件 添加属性 点击滑动单元格时触发的事件 bind:click="onSwipeCellClick"
  5. 需要对单元格实例数组进行遍历,遍历以后获取每一个实例,让每一个实例调用 close 方式即可

示例

  1. 新建文件夹 SwiperCell.js
Page({data: {swipeCellQueue: [], //用来存储滑动单元格实例 },// 当用户打开滑块时触发swiperCellOpen(event) {// 获取单元格实例const instance = this.selectComponent(`#${event.target.id}`)// 将实例追加到数据中this.data.swipeCellQueue.push(instance)},// 给页面绑定 点击事件onSwipeCellPage() { this.onSwipeCellCommonClick() },// 点击滑动单元格时触发的事件onSwipeCellClick() { this.onSwipeCellCommonClick() },onSwipeCellCommonClick() {// 需要对单元格实例数组进行遍历,遍历以后获取每一个实例,让每一个实例调用 close 方式即可this.data.swipeCellQueue.forEach((instance) => {instance.close()})// 将滑动单元格数组重置为空this.data.swipeCellQueue = []}
})
  1. 然后在使用文件 wxml 中 最外层的 view 绑定 页面点击事件 bindtap="onSwipeCellPage"
  2. 给 swipe-cell 绑定一个 id <van-swipe-cell class="goods-swipe" right-width="{{ 65 }}" id="swipe-cell-{{item.id}}">
  3. 给 swipe-cell 绑定open和click事件 <van-swipe-cell class="goods-swipe" right-width="{{ 65 }}" id="swipe-cell-{{item.id}}" bind:open="swiperCellOpen" bind:click="onSwipeCellClick">
  4. 在 使用文件 js 中 引入 Behaviors
  5. 然后在 onHide 方法 引入 在页面隐藏的时候,需要让删除滑块自动弹回
import { ComponentWithStore } from 'mobx-miniprogram-bindings'
import { userStore } from '@/stores/userStore'
import { reqDelCartGoods } from "@/api/cart"import { swipeCellBehavior } from "@/behaviors/swiperCell"
const computedBehavior = require("miniprogram-computed").behavior
ComponentWithStore({behaviors: [ swipeCellBehavior],storeBindings: {store: userStore,fields: ['token']},data: {cartList: []},methods: {//  如果使用 Compoent 方法来构建页面// 生命周期钩子函数 需要在 methods 中才可以// 删除商品async delCartGoods(evnet) {// 要删除的idlet { id } = evnet.currentTarget.dataset// 自己封装的 modal方法const isOk = await wx.modal({title: '提示',content: "您确定要删除吗?"})if (!isOk) {return}const res = await reqDelCartGoods(id)if (res.code === 200) {....}},onHide() {this.onSwipeCellCommonClick()}}
})
http://www.lryc.cn/news/405382.html

相关文章:

  • 【vluhub】log4j注入漏洞 CVE-2021-44228
  • Redis核心技术与实战学习笔记
  • 力扣经典题目之->设计循环队列 的超详细讲解与实现
  • 【数据结构】排序算法——Lesson2
  • Ubuntu编译ffmpeg并添加cmake工程
  • Vue.js[组件(Component)]
  • 基于微信小程序+SpringBoot+Vue的校园自助打印系统(带1w+文档)
  • qt设置过滤器
  • 线上环境服务器CPU飙升排查
  • unity文字||图片模糊
  • 香薰学习笔记
  • iOS ------ weak的基本原理
  • 实时更新UI界面
  • 为什么Spring不推荐@Autowired用于字段注入
  • 【北京迅为】《i.MX8MM嵌入式Linux开发指南》-第三篇 嵌入式Linux驱动开发篇-第三十九章 Linux MISC驱动
  • 基于MobileNetv2的垃圾分类函数式自动微分-昇思25天打卡
  • STM32CubeIDE(CAN)
  • GO Channel使用详解(各种场景下的最佳实践)
  • SwiftUI 5.0(iOS 17)滚动视图的滚动目标行为(Target Behavior)解惑和实战
  • picker 构建记录
  • Docker部署kafka,Docker所在宿主机以外主机访问
  • 控制欲过强的Linux小进程
  • ​探讨元宇宙和VR虚拟现实之间的区别​
  • Docker Desktop安装
  • 《Towards Black-Box Membership Inference Attack for Diffusion Models》论文笔记
  • vscode调试nextjs前端后端程序、nextjs api接口
  • 《SeTformer Is What You Need for Vision and Language》
  • [保姆级教程]uniapp安装使用uViewUI教程
  • 网络安全法规对企业做等保有哪些具体规定?
  • Java开发中超好用Orika属性映射工具