购物车商品数量为0判断是否删除

当编辑商品的数量为1,再减的话,我们搞个模态提示,让用户决定是否要删除这个商品?
在这里插入图片描述

  //商品数量的编辑功能
    handleItemNumEdit(e){
   
        const {
   operation,id}=e.currentTarget.dataset;
        console.log(operation,id);
        let {
   cart}=this.data;
        let index=cart.findIndex(v=>v.id===id);
        if(cart[index].num===1 && operation === -1){
   
            wx.showModal({
   
              title: '系统提示',
              content: '你是否要删除?',
              cancelColor:'cancelColor',
              success: (res) => {
   
                if (res.confirm) {
   
                  cart.splice(index,1);
                  this.setCart(cart);
                }
              }
            })
        }else{
   
            cart[index].num+=operation;
            this.setCart(cart);
        }
    },

前端开发-微信小程序wx.showModal的使用方法

wx.showModal({
   
	title:'提示',
	content:'(提示的内容)',
	showCancel:true, //默认为true,false去掉取消按钮
	confirmText:'',//默认是“确认”
	confirmColor:'',//确认文字的颜色
	success:function(res)
	{
   
		if(res.cancel)
		{
   
			//点击取消按钮
		}else if(res.confirm)
		{
   
			//点击确认按钮
		}
	}
})

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-08 20:54:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-08 20:54:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-02-08 20:54:02       82 阅读
  4. Python语言-面向对象

    2024-02-08 20:54:02       91 阅读

热门阅读

  1. pytorch的安装步骤

    2024-02-08 20:54:02       57 阅读
  2. 关于php匿名函数中的use

    2024-02-08 20:54:02       51 阅读
  3. 排序(2)(希尔排序)

    2024-02-08 20:54:02       51 阅读
  4. 【C语言进阶篇】原码、反码、补码

    2024-02-08 20:54:02       54 阅读
  5. 2021-07-02 51单片机按键控制LED灯逐个点亮

    2024-02-08 20:54:02       57 阅读
  6. c++基本介绍

    2024-02-08 20:54:02       50 阅读
  7. Qt PCL学习(文章链接汇总)

    2024-02-08 20:54:02       55 阅读