Skip to content

Rate 评分

用于通过星级或自定义图标表达评分结果,支持交互评分、只读展示等场景。

交互式调试

🔧调试模式Playground

基础用法

vue
<script setup lang="ts">
import { ref } from 'vue'

const score = ref(3)
</script>

<template>
  <lk-rate v-model="score" />
</template>

再次点击清零

启用 allowClear 后,点击当前已选值可直接清零。

vue
<lk-rate v-model="score" allow-clear @clear="handleClear" />

clear 会返回 { oldValue, index, event },适合做撤销提示或埋点。

只读与禁用

vue
<template>
  <lk-rate :model-value="4" readonly />
  <lk-rate :model-value="2" disabled />
</template>

自定义图标与颜色

vue
<lk-rate
  v-model="score"
  icon="star-fill"
  icon-void="star"
  color="#f5a623"
  color-void="#d4d4d8"
/>

自定义数量与尺寸

vue
<template>
  <lk-rate v-model="score" :count="8" :size="64" />
</template>

推荐示例

1) 直接复用项目 Demo(推荐)

vue
<script setup lang="ts">
import RateDemo from '@/components/demos/rate-demo.vue'
</script>

<template>
  <RateDemo />
</template>

2) 在业务页中按需组合

vue
<template>
  <view class="page-demo">
    <lk-rate />
  </view>
</template>

API

Props

参数说明类型默认值
modelValue当前评分值number0
count图标总数量number5
disabled是否禁用booleanfalse
readonly是否只读booleanfalse
allowClear点击当前值时是否允许清零booleantrue
size图标尺寸,数字按 rpx 处理string | number48
color选中颜色string''
colorVoid未选中颜色string''
icon选中图标名string''
iconVoid未选中图标名string''
prop表单字段名string''
id根节点 idstring''
customClass根节点自定义类名string | object | array
customStyle根节点自定义样式string | object

Events

事件名说明参数
update:modelValue评分变化(value: number) => void
change评分变化后的回调(value: number, oldValue?: number) => void
click点击可交互图标时触发,早于 change({ value, oldValue, index, event }) => void
clear点击当前评分并清零时触发({ oldValue, index, event }) => void
click-disabled点击禁用或只读评分时触发({ value, index, disabled, readonly, event }) => void

Slots

使用建议

TIP

展示历史评分或服务评分结果时,优先使用 readonly,避免用户误以为仍可编辑。

基于 MIT 协议开源 · 粤ICP备2022114240号-3

Rate 评分

正在连接预览服务...

请先运行 pnpm run dev:h5