完整代码地址:
https://github.com/tuihou1233...
html模板代码
<div class="starBox">
<span class="grey">
<i class="fa fa-star" v-for="n in 5"></i>
</span>
<span style="color:#ff9a0d;">
<i class="fa fa-star" v-for="n in starFun(item,0)"></i>
<i class="fa fa-star-half" v-for="m in starFun(item,1)"></i>
</span>
</div>
vue中相应方法代码
methods:{
starFun:function(item,index){
var num=item.rating+"";
var a;
if(index==0){
if(num.indexOf(".")<0){
a=num;
}
else{
a=num.split(".")[0];
}
}
else{
if(num.indexOf(".")<0 || num.split(".")[1]<5 ){
a=0;
}
else{
a=1;
}
}
console.log(a);
return a;
}
}
相关分类