vue 五星评分及数据为遍历

div class="star" style="float: right" >
  <span v-for="(itemClass,index) in y.itemClasses" :class="itemClass" data="1" class="star-item" :track-by="index" ></span>
</div>

遍历数据并重新赋值

let list = response.data.data.data;
that.url = http;

list.forEach(item=>{
  item.itemClasses = that.itemClasses(item.certificate_level)
});
 

methods:{
  itemClasses(score_){
    score_ = typeof score_ === 'number'?score_:Number(score_);
    // this.score>5 ? this.score=5 : this.score;
    score_ = score_>=5 ? 5 : score_;
    let result = [];
    let  score =Math.floor(score_ * 2) / 2;
    let hasDecimal = score % 1 !==0;
    let integer = Math.floor(score);
    for(let i=0;i<integer;i++){
      result.push("on");
    }
    if(hasDecimal){
      result.push("half");
    }
    while(result.length <5){
      result.push("off");
    }
    return result;

},

样式

.star-item{
  display: inline-block;
  background-repeat:no-repeat ;
  width: 0.09rem;
  height: 0.09rem;
  /*margin-right: 0.rem;*/
  background-size:100% ;
}
.star-item.on{
  background-image: url("../../images/_20171226164030.png");
}

.star-item.half{
  background-image: url("../../images/0171226164041.png");
}
.star-item.off{
  background-image: url("../../images/171226164044.png");
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中进行数据处理和遍历时,可以采取一些优化方法来提高性能和效率。下面是一些常见的优化技巧: 1. 使用v-for的key属性:在使用v-for指令进行列表渲染时,为每个项设置唯一的key属性。这样Vue可以跟踪每个项的变化,提高渲染效率。 2. 避免在模板中进行复杂的计算:尽量避免在模板中进行复杂的计算或方法调用。最好在computed属性中对数据进行处理,然后在模板中直接引用computed属性。 3. 数据分页和懒加载:如果列表数据非常庞大,可以考虑进行数据分页和懒加载。只渲染当前可见区域的数据,减少渲染的负担。 4. 使用Object.freeze():对于不会被修改的数据,可以使用Object.freeze()方法冻结对象,防止不必要的监测和更新操作。 5. 合理使用v-if和v-show:根据具体情况选择使用v-if还是v-show。v-if适用于频繁切换条件的情况,而v-show适用于频繁切换显示/隐藏的情况。 6. 避免过多的watcher:当数据变化时,Vue会触发watcher来更新视图。如果有大量的watcher存在,会降低性能。可以考虑使用computed属性或手动优化数据流,减少watcher的使用。 7. 使用虚拟滚动:对于大型列表,可以考虑使用虚拟滚动技术,只渲染可见区域的内容,降低渲染的负担。 这些是一些常见的Vue数据处理和遍历优化方法,根据具体情况选择适合的优化策略可以提高应用的性能和用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值