上海十套房
上海十套房
  • 发布:2021-05-17 11:21
  • 更新:2022-07-25 17:44
  • 阅读:1738

uni-rate 评分 点击评分失效问题解决

分类:uni-app
  • 定位到 _getRateCount(获取星星个数) 方法,进行替换,替换代码如下。

    /**  
    * 获取星星个数  
    */  
    _getRateCount(clientX) {  
    this._getSize()  
    const size = Number(this.size)  
    if(size === NaN){  
    return new Error('size 属性只能设置为数字')  
    }  
    const rateMoveRange = clientX - this._rateBoxLeft  
    let index = parseInt(rateMoveRange / (size/2 + this.marginNumber))  
    index = index < 0 ? 0 : index;  
    index = index > this.max ? this.max : index;  
    const range = parseInt(rateMoveRange - (size/2 + this.marginNumber) * index);  
    let value = 0;  
    if (this._oldValue === index && !this.PC) return;  
    this._oldValue = index;  
    if (this.allowHalf) {  
    if (range > (size / 2)) {  
      value = index + 1  
    } else {  
      value = index + 0.5  
    }  
    } else {  
    value = index + 1  
    }  
    
    value = Math.max(0.5, Math.min(value, this.max))  
    this.valueSync = value  
    this._onChange()  
    },

原因

rpx和px问题

let index = parseInt(rateMoveRange / (size + this.marginNumber)) -> let index = parseInt(rateMoveRange / (size/2 + this.marginNumber))
const range = parseInt(rateMoveRange - (size + this.marginNumber) index); -> const range = parseInt(rateMoveRange - (size/2 + this.marginNumber) index

0 关注 分享

要回复文章请先登录注册

8***@qq.com

8***@qq.com

有用, const range = parseInt(rateMoveRange - (size/2 + this.marginNumber) * index);
原本没有size/2 直接是size
2022-07-25 17:44