uniapp 左滑删除功能

文章介绍了在uni-app中结合uni-swipe-action和uni-swipe-action-item组件来创建删除功能。通过在data中定义options,配置滑动操作项,然后利用Vuex的mapMutations方法映射deleteGood方法,实现在点击删除按钮后调用删除商品的逻辑。在cartStore的mutations里,找到要删除的商品并从cart数组中移除,最后更新存储。
摘要由CSDN通过智能技术生成

使用uni-swipe-action和uni-swipe-action-item组件,两个都要进行注册

 配置options信息

data() {
			return {
				options2: [{
					text: '删除',
					style: {
						backgroundColor: '#C00000'
					}
				}]
			};
		}

点击之后,操作仓库数据

import {mapMutations} from 'vuex'
export default{
    methods:{
        ...mapMutations('cartStore', ['deleteGood']),
        // 购物车删除产品
			deleteGoodDetail(goodDetail) {
				this.deleteGood(goodDetail)
			},
    }
    
}

cartStore

state:()=>({
	cart:JSON.parse(uni.getStorageSync('cart') || '[]')
}),
mutations:{
    deleteGood(state,goods){
			var goodIndex = 0
			var result = state.cart.find(function(currentValue, index,arr){
				goodIndex = index
				return currentValue.goods_id == goods.goods_id				
			})
			state.cart.splice(goodIndex,1)
			Storage.setCartStorage(state.cart)
		}

}

 效果

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值