评星功能
直接上代码
starClasses () {
const {score} = this //分数,例如4.7
const scs = []
// 向scs中添加n个CLASS_ON
const scoreInteger = Math.floor(score)
for (let i = 0; i < scoreInteger; i++) {
scs.push(CLASS_ON)
}
// 向scs中添加0/1个CLASS_HALF
if(score*10-scoreInteger*10>=5) {
scs.push(CLASS_HALF)
}
// 向scs中添加n个CLASS_OFF
while(scs.length<5) {
scs.push(CLASS_OFF)
}
return scs
}