Skip to content

Rate 评分

介绍

用于快速的评级操作,或对评价进行展示。

基础用法

html
<template>
  <nut-rate v-model="value"></nut-rate>
</template>
ts
const value = ref(3);

半星

html
<template>
  <nut-rate v-model="value" allow-half></nut-rate>
</template>
ts
const value = ref(3.5);

自定义icon

html
<template>
  <nut-rate v-model="value" custom-icon="heart-fill"></nut-rate>
</template>

自定义数量

html
<template>
  <nut-rate v-model="value" :count="6"></nut-rate>
</template>

自定义颜色

html
<template>
  <nut-rate v-model="value" active-color="#ffc800"></nut-rate>
</template>

禁用状态

html
<template>
  <nut-rate v-model="value" disabled></nut-rate>
</template>

只读状态

html
<template>
  <nut-rate v-model="value" readonly></nut-rate>
</template>

自定义尺寸

html
<template>
  <nut-rate v-model="value" size="35"></nut-rate>
</template>

事件演示

html
<template>
  <nut-rate v-model="value" @change="onChange"></nut-rate>
</template>
ts
const value = ref(3);

function onChange(val: number) {
  console.log("change", val);
}

API

Props

参数说明类型可选值默认值
v-model当前 starnumber / string-0
countstar 总数number / string-5
active-color图标选中颜色string-#fa200c
void-color图标未选中颜色string-#cccccc
allow-half是否半星boolean-false
readonly是否只读boolean-false
disabled是否禁用boolean-false
spacing间距number / string-14
size尺寸大小(如 20px 2em 2remnumber / string--
custom-icon自定义图标string-star-fill-n

Events

事件名说明类型
change当前分值修改时时触发的事件(value: number) => void

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值
--nut-rate-icon-colorvar(--nut-primary-color)
--nut-rate-icon-void-colorvar(--nut-disable-color)

MIT Licensed