vue五星评分展示效果
时间: 2024-08-14 11:03:24 浏览: 26
Vue.js中展示五星评分效果通常通过模板和数据驱动的方式实现。你可以创建一个包含五个星型图标或div元素的数组,并绑定到一个动态值上,比如用户评价的分数。下面是一个简单的示例:
```html
<template>
<div class="star-rating">
<span v-for="(star, index) in 5" :key="index" :class="{ full: rating >= index + 1 }">
{{ star === 1 ? '★' : (star === 2 ? '☆' : (star === 3 ? '☇' : (star === 4 ? '☈' : '☉')) }}
</span>
</div>
</template>
<script>
export default {
data() {
return {
rating: 0,
};
},
};
</script>
<style scoped>
.star-rating span {
display: inline-block;
width: 20px;
height: 20px;
margin-right: 5px;
}
.full {
color: gold;
}
</style>
```
在这个例子中,`rating`字段表示用户评分,每增加一个星就是+1。`:class="{ full: rating >= index + 1 }"`会根据评分给每个星分配full类名,使其呈现金色填充,达到评分的效果。