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

当编辑商品的数量为1,再减的话,我们搞个模态提示,让用户决定是否要删除这个商品?
购物车商品数量为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)
		{
			//点击确认按钮
		}
	}
})

你可能感兴趣的:(分布式小程序电商2,前端,javascript,vue.js)