vue 五星评价插件


html:

<div class="starBox" ref="star1">
    <div class="star" v-for="(item,index) in starArr1" :key="index" @click="starClick1(index)">
      <img :src="'../../static/images/'+item.imgSrc">
    </div>
 </div>

js:

export default {
  data () {
    return {
      starArr1: [{imgSrc: 'star1.png'}, {imgSrc: 'star1.png'}, {imgSrc: 'star1.png'}, {imgSrc: 'star1.png'}, {imgSrc: 'star1.png'}]
    }
  },
  methods: {
    starClick1 (index) {
      this.starArr1.forEach((element, i) => {
        this.$set(element, 'imgSrc', 'star1.png')
        if (i <= index) {
          this.$set(element, 'imgSrc', 'star2.png')
        }
      })
      this.commentScore[0] = index + 1
    }
 }
}

css:

.starBox {
  display: flex;
  display: -webkit-flex;
}
.starActive {
  color: red;
}
.star img {
  width: 40px;
  height: 20px;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM