思路: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);
}
})
}