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;
}

 

相关文章:

  • 2022-02-20
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
猜你喜欢
  • 2021-09-04
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-08-10
  • 2022-02-25
相关资源
相似解决方案