<div class="star" :class="starType">
<span v-for="itemClass in itemClasses" :class="itemClass" class="star-item" track-by="$index"></span>
</div>
props: {
size:{
type:Number
},
score:{
type:Number
}
}
starType() {
return 'star-'+this.size;
}
.star-48 {
width: 20px;
height: 20px;
margin-right: 22px;
background-size: 20px 20px;
}
.star-36 {
width: 15px;
height: 15px;
margin-right: 6px;
background-size: 15px 15px;
}
.star-24 {
width: 10px;
height: 10px;
margin-right: 3px;
background-size: 10px 10px;
}
const LENGTH = 5;
const CLS_ON = 'on';
const CLS_HALF = 'half';
const CLS_OFF = 'off';
itemClasses() {
let result = [];
let score = Math.floor(this.score*2)/2;
let hasDecimal = score%1 !== 0;
let integer = Math.floor(score);
for (var i = 0; i < integer; i++) {
result.push(CLS_ON);
}
if(hasDecimal) {
result.push(CLS_HALF);
}
while (result.length<LENGTH) {
result.push(CLS_OFF);
}
return result;
}
.star-48 .on {
background-image: url('star48_on@2x.png')
}
.star-48 .half {
background-image: url('star48_half@2x.png')
}
.star-48 .off {
background-image: url('star48_off@2x.png')
}
<template>
<div class="star" :class="starType">
<span v-for="itemClass in itemClasses" :class="itemClass" class="star-item" track-by="$index"></span>
</div>
</template>
<script type="text/javascript">
const LENGTH = 5;
const CLS_ON = 'on';
const CLS_HALF = 'half';
const CLS_OFF = 'off';
export default {
props: {
size:{
type:Number
},
score:{
type:Number
}
},
computed:{
starType() {
return 'star-'+this.size;
},
itemClasses() {
let result = [];
let score = Math.floor(this.score*2)/2;
let hasDecimal = score%1 !== 0;
let integer = Math.floor(score);
for (var i = 0; i < integer; i++) {
result.push(CLS_ON);
}
if(hasDecimal) {
result.push(CLS_HALF);
}
while (result.length<LENGTH) {
result.push(CLS_OFF);
}
return result;
}
}
};
</script>
<style type="text/css">
.star {
font-size: 0;
}
/* .star-48 {
width: 20px;
height: 20px;
margin-right: 22px;
background-size: 20px 20px;
} */
.star-48 : last-chlid {
margin-right: 0;
}
.star-48 .on {
background-image: url('star48_on@2x.png')
}
.star-48 .half {
background-image: url('star48_half@2x.png')
}
.star-48 .off {
background-image: url('star48_off@2x.png')
}
.star-36 {
width: 15px;
height: 15px;
margin-right: 6px;
background-size: 15px 15px;
}
.star-36 .no {
background-image: url('star36_on@2x.png')
}
.star-36 .half {
background-image: url('star36_half@2x.png')
}
.star-36 .off {
background-image: url('star36_off@2x.png')
}
.star-24 {
width: 10px;
height: 10px;
margin-right: 3px;
background-size: 10px 10px;
}
.star-24 .no {
background-image: url('star24_on@2x.png')
}
.star-24 .half {
background-image: url('star24_half@2x.png')
}
.star-24 .off {
background-image: url('star24_off@2x.png')
}
.star-item {
display: inline-block;
background-repeat: no-repeat;
width: 20px;
height: 20px;
margin-right: 22px;
background-size: 20px 20px;
}
</style>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有