小程序购物车右上角数字显示与消失

思路:1、调用接口,获取数值 2、判断数值是否为0,如果数值为0,调用wx.removeTabBarBadge()函数,如果数值不为0,调用wx.setTabBarBadge()函数;如下

   /**
     * 获取用户购物车数量
     */
    set_nav_cart_num:function () {
        var that = this;
        that.post_ajax('/index/shop_cart_namber',{ 
            user_id: that.user_id,
        }, function (res, status) {
            // console.log(res)
            if (status == 200) {
                if(res != 0){
                    wx.setTabBarBadge({
                        index: 2,
                        text: res + '',
                    })
                }else{
                    wx.removeTabBarBadge({
                        index: 2,
                        text: '',
                    })
                }
                console.log(res);
            } else {
                app.basic_dialog(res);
            }
        })
        
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值