showTabBarReddot or setTabBarBadge无效没报错?
发布于 5 年前 作者 yanyong 11808 次浏览 来自 官方Issues

最近开发个小程序,需要实现其它用户发送评论就在消息的tab那里显示个红点的功能,但是无论是调用showTabBarReddot还是setTabBarBadge,tabbar都没有任何反应,真不知道该如何解决┭┮﹏┭┮。下面发一下代码给大家看看。

referComment: function (e){
    // 只能用缓存来传评论数据
    var criticism = wx.getStorageSync('criticism')
    var userInfo = wx.getStorageSync('userInfo')
    var commentCreatTime = utils.formatTime(new Date())
    var result = [userInfo.nickName, userInfo.avatarUrl, commentCreatTime, e.detail.value.comment, this.data.touristID, this.data.figureID, []]
    criticism.push(result)
    if(result[3]){
      this.refer(criticism, 'comment')
      news.add({
        data:{
          acceptor: this.data.creatorID,
          writer: [userInfo.nickName, userInfo.avatarUrl,this.data.touristID],
          content: [e.detail.value.comment, this.data.figureID],
          time: commentCreatTime,
          url: `/pages/details/details?id=${this.data.pageID}`,
          newsType:'消息回复',
          essayType: this.data.type
        }

      })    // 意思是用户提交了评论后,先判断是否为空评论,将评论信息写入数据库,然后在消息的tabbar那里显示红点

      wx.showTabBarRedDot({
        index: 1,
        success: res => { console.log(res) },
        fail: res => { console.error }
      })
}

<form bindsubmit='referComment' report-submit='{{true}}'>
     <view class='form'>
      <textarea class='comment' name='comment' value='{{content}}' placeholder-style='color:#000;width:800rpx;z-index:-1' focus='{{focus}}' bindfocus="focusText"  bindblur="blurText">{{placeholder}}</textarea>
      <view class='uploadImages'>    
        <view class="addimages">
          <block wx:for='{{figures}}' wx:key="*this">
            <image src='{{figures[index]}}' style='margin:0 0 0 20rpx'></image>
          </block>
          <image bindtap='addimages' src="/images/plus-square-fill.png" style='width:50px;height:50px;margin-left: 20rpx;'></image>
          <image bindtap='delimages' src="/images/minus-square-fill.png" style='width:50px;height:50px'></image>
        </view>
      </view>
      <button form-type='submit' type='primary' wx:if='{{signIn}}' style='background-color:#8de7bb;width:90%;color: white;' bindtap='reddot'>发送</button>
    </view>
</form>

但无论怎么搞,那个api不报错也没效果,都不知道该怎么办……

1 回复

我记得要在tabbar的页面调用才有效果

回到顶部