赞
踩
- 在当前页面整个 view 中 给页面绑定 点击事件
bindtap="onSwipeCellPage"
- 给 van-swipe-cell 组件设置 id (for循环可以添加
id="swip-cell-{{item.id}}"
)- van-swipe-cell 组件 添加属性 当用户打开滑块时触发
bind:open="swiperCellOpen"
- van-swipe-cell 组件 添加属性 点击滑动单元格时触发的事件
bind:click="onSwipeCellClick"
- 需要对单元格实例数组进行遍历,遍历以后获取每一个实例,让每一个实例调用 close 方式即可
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 = [] } })
bindtap="onSwipeCellPage"
<van-swipe-cell class="goods-swipe" right-width="{{ 65 }}" id="swipe-cell-{{item.id}}">
<van-swipe-cell class="goods-swipe" right-width="{{ 65 }}" id="swipe-cell-{{item.id}}" bind:open="swiperCellOpen" bind:click="onSwipeCellClick">
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) { // 要删除的id let { 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() } } })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。