- 利用数组渲染的原理,把星星利用标识来区分
- 利用循环渲染的方式,再判断渲染出哪种型状的星星
<template>
<view class="score">
<view v-for="(item,index) in handleScoreList" :key="index">
<view class="stars iconfont icon-xingxing1" v-if="item == 2"></view>
<view class="stars iconfont icon-bankexingxing" v-if="item == 1"></view>
<view class="stars iconfont icon-kongxinxingxing" v-if="item == 0"></view>
</view>
{{score}}
</view>
</template>
<script>
export default {
props:['score'],
data() {
return {
scoreList:[0,0,0,0,0],
scoreItem: this.score>=10?5:this.score/2
};
},
computed: {
handleScoreList() {
for(let i=0; parseInt(this.scoreItem)-1 >= i; i++){
this.scoreList[i] = 2
}
if(!Number.isInteger(this.scoreItem)){
this.scoreList[Math.floor(this.scoreItem)] = 1
}
return this.scoreList
}
},
}
</script>
<style lang="scss" scoped>
.score{
display: flex;
color: #333;
align-items: center;
font-size: 25rpx;
.stars{
font-size: 25rpx;
margin-right: 10rpx;
color: #ffc82a;
}
}
</style>