Skip to content

Rate 评分

介绍

评价中的评分操作。

基础用法

通过 v-model 绑定选中的评分。

html
<vd-rate v-model="rate" />
ts
const rate = ref(0);

评分个数

通过 count 属性自定义评分个数。

html
<vd-rate v-model="rate" :count="7" />
ts
const rate = ref(0);

自定义图标

通过 icon 设置评分的激活图标,inactive-icon 设置评分的未激活图标。

html
<vd-rate v-model="rate" icon="love-fill" />
ts
const rate = ref(0);

自定义颜色

通过 color 设置评分的激活颜色,inactive-color 设置评分的未激活颜色。

html
<vd-rate v-model="rate" color="#f40" />
ts
const rate = ref(0);

自定义单个评分颜色

通过 color 设置评分的激活颜色,inactive-color 设置评分的未激活颜色。

html
<vd-rate v-model="rate">
  <vd-rate-item
    v-for="(_, index) in 5"
    :key="index"
    :index="index"
    :color="colors[index]"
  />
</vd-rate>
ts
const colors = [
  'rgba(255, 210, 30, 0.5)',
  'rgba(255, 210, 30, 0.75)',
  '#ffd21e',
  '#ff976a',
  '#ee0a24',
];

const rate = ref(0);

分段选择

通过 segments 开启分段选择,例如分 2 段则每段评分 1 / 2 = 0.5

html
<vd-rate v-model="rate" :segments="2" />
ts
const rate = ref(0);

只读状态

通过 readonly 设置只读状态,只读状态下无法进行评分。

html
<vd-rate v-model="rate" readonly />
ts
const rate = ref(0);

禁用状态

通过 disabled 设置禁用状态,禁用状态下无法进行评分。

html
<vd-rate v-model="rate" disabled />
ts
const rate = ref(0);

使用插槽

通过插槽可以自定义评分的激活/未激活图标。

html
<vd-rate v-model="rate">
  <vd-rate-item v-for="(num, index) in 3" :key="num" :index="index">
    <template #inactive><vd-icon name="star" /></template>
    <template #active><vd-icon name="star-fill" /></template>
  </vd-rate-item>
</vd-rate>
ts
const rate = ref(0);

API

Rate Props

参数说明类型默认值
v-model选中分值string | number-
count评分个数string | number5
segments选择段数string | number1
size图标大小string | number26
icon激活图标IconsNamestar-fill
inactive-icon未激活图标IconsName-
color激活颜色string-
inactive-color未激活颜色string-
readonly是否只读booleanfalse
disabled是否禁用booleanfalse
swipeable是否开启左右滑动手势booleantrue
clickable是否允许点击更改分值booleantrue

RateItem Props

参数说明类型默认值
segments选择段数string | number-
size图标大小string | number-
icon激活图标IconsName-
inactive-icon未激活图标IconsName-
color激活颜色string-
inactive-color未激活颜色string-
clickable是否允许点击更改分值boolean-
index索引,循环时设置该值防止顺序异常string-

代替原始 Props

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

Rate Events

事件名说明回调参数
click点击时触发MouseEvent
change评分改变时触发number
click-item点击评分时触发RateOnClickItemEvent
swipe-change手势滑动改变时触发RateOnSwipeChangeEvent

RateItem Events

事件名说明回调参数
click点击时触发MouseEvent

Rate Slots

名称说明
default自定义内容

RateItem Slots

名称说明
active激活图标
inactive未激活图标

赣ICP备2025061025号-1