Skip to content

StarRating 星级评分

SVG 绘制的星级评分组件,支持半星与自定义颜色尺寸。

基础用法

只读,分数:3.5
vue
<template>
  <MStarRating :model-value="3.5" />
</template>

可交互打分

支持半星:点击星星左半区给 0.5 分,右半区给整分。

当前分数:0
vue
<script setup>
import { ref } from 'vue'
const score = ref(0)
</script>

<template>
  <MStarRating v-model="score" :readonly="false" :size="28" />
</template>

自定义样式

vue
<template>
  <MStarRating :model-value="4" fill-color="#FF9900" empty-color="#FFE4B8" />
  <MStarRating :model-value="2.5" fill-color="#3366FF" :size="24" />
  <MStarRating :model-value="5" fill-color="#22C55E" :size="32" :gap="4" />
</template>

Props 属性

属性名类型默认值说明
modelValuenumber-当前分数(支持 0.5 步进)
maxStarsnumber5总星数
sizenumber20单个星星尺寸(px)
gapnumber2星星间距(px)
fillColorstring'#FBBF24'实心星颜色
emptyColorstring'#D1D5DB'空心星颜色
strokeWidthnumber1.5描边宽度
readonlybooleantrue是否只读
wrapperClassstring''容器自定义 class

Events 事件

事件名参数说明
update:modelValue(value: number)分数变化时触发

Released under the MIT License.