Rate rating

introduce

Used to rate things.

Code Demo

Basic usage

Bind the current rating value through v-model.

<z-rate v-model="value" />
import { ref } from 'vue';
const value = ref(3);

Custom icon

Use the icon attribute to set the icon when selected, and the void-icon attribute to set the icon when not selected.

<z-rate v-model="value" icon="heart-fill" void-icon="heart" />

Custom style

Use the size attribute to set the size of the icon, the color attribute to set the color when it is selected, and void-color to set the color when it is not selected.

<z-rate
v-model="value"
:size="35"
color="#ffd21e"
void-icon="star"
void-color="#eee"
/>

Half star

Half stars can be selected by setting the allow-half property.

<z-rate v-model="value" allow-half />
import { ref } from 'vue';
const value = ref(2.5);

Custom quantity

Set the total number of ratings via the count attribute.

<z-rate v-model="value" :count="6" />

Can be cleared

When the clearable property is set to true, clicking the same value again will reset the value to 0.

<z-rate v-model="value" clearable />

Disabled state

Disable scoring via the disabled attribute.

<z-rate v-model="value" disabled />

Read-only status

Set the rating to read-only status via the readonly attribute.

<z-rate v-model="value" readonly />

Read-only status displays decimals

After setting the readonly and allow-half properties, the Rate component can display any decimal result.

<z-rate v-model="value" readonly allow-half />
import { ref } from 'vue';
const value = ref(3.3);

Listen for change events

When the rating changes, the change event is triggered.

<z-rate v-model="value" @change="onChange" />
import { ref } from 'vue';
import { useToast } from '../../uni_modules/zebra-ui'
const toast = useToast()
const value = ref(3);
const onChange = (value) => showToast('Current value: ' + value);

API

Props

ParametersDescriptionTypeDefault value
v-modelCurrent scorenumber-
countTotal number of iconsnumber | string5
sizeIcon size, default unit is pxnumber | string40rpx
gutterIcon spacing, default unit is pxnumber | string8rpx
colorColor when selectedstring#ee0a24
void-colorColor when not selectedstring#c8c9cc
disabled-colorDisabled colorstring#c8c9cc
iconThe icon name or image link when selected, equivalent to the name attribute of the Icon componentstringstar-fill
void-iconThe icon name or image link when not selected, equivalent to the name attribute of the Icon componentstringstar
icon-prefixIcon class name prefix, equivalent to the class-prefix attribute of the Icon componentstringz-icon
allow-halfWhether to allow half selectionbooleanfalse
clearableWhether to allow clearing after clicking againbooleanfalse
readonlyWhether it is in read-only status. The rating cannot be modified in read-only statusbooleanfalse
disabledWhether to disable ratingbooleanfalse
touchableWhether ratings can be selected through swipe gesturesbooleantrue

Events

Event nameDescriptionCallback parameters
changeEvent triggered when the current score changescurrentValue: number

Theme customization

Style variables

The component provides the following CSS variables, which can be used to customize styles. For usage, please refer to ConfigProvider component.

NameDefaultDescription
--z-rate-icon-size40rpx-
--z-rate-icon-guttervar(--z-padding-base)-
--z-rate-icon-void-colorvar(--z-gray-5)-
--z-rate-icon-full-colorvar(--z-danger-color)-
--z-rate-icon-disabled-colorvar(--z-gray-5)-