Skip to content

Rate - Vant 4

Rate ​

Intro ​

The rate component is used for rating things.

Install ​

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { Rate } from'vant'; const app = createApp(); app.use(Rate);

Usage ​

Basic Usage ​

html
js
import { ref } from'vue'; exportdefault { setup() { const value = ref(3); return { value }; }, };

Custom Icon ​

html

Custom Style ​

html

Half Star ​

html
js
import { ref } from'vue'; exportdefault { setup() { const value = ref(2.5); return { value }; }, };

Custom Count ​

html

Clearable ​

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

html

Disabled ​

html

Readonly ​

html

Readonly Half Star ​

html
js
import { ref } from'vue'; exportdefault { setup() { const value = ref(3.3); return { value }; }, };

Change Event ​

html
javascript
import { ref } from'vue'; import { showToast } from'vant'; exportdefault { setup() { const value = ref(3); constonChange = (value) => showToast('current value:' + value); return { value, onChange, }; }, };

API ​

Props ​

AttributeDescriptionTypeDefault
v-modelCurrent ratenumber-
countCount*numberstring*
sizeIcon size*numberstring*
gutterIcon gutter*numberstring*
colorSelected colorstring#ee0a24

| void-color | Void color | string | #c8c9cc |

| disabled-color | Disabled color | string | #c8c9cc |

| icon | Selected icon | string | star | | void-icon | Void icon | string | star-o | | icon-prefix | Icon className prefix | string | van-icon | | allow-half | Whether to allow half star | boolean | false | | clearable v4.6.0 | Whether to allow clear when click again | boolean | false | | readonly | Whether to be readonly | boolean | false | | disabled | Whether to disable rate | boolean | false | | touchable | Whether to allow select rate by touch gesture | boolean | true |

Events ​

EventDescriptionParameters
changeEmitted when rate changedcurrentValue: number

Types ​

The component exports the following type definitions:

ts
importtype { RateProps } from'vant';

Theming ​

CSS Variables ​

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

NameDefault ValueDescription
--van-rate-icon-size20px-
--van-rate-icon-guttervar(--van-padding-base)-
--van-rate-icon-void-colorvar(--van-gray-5)-
--van-rate-icon-full-colorvar(--van-danger-color)-
--van-rate-icon-disabled-colorvar(--van-gray-5)-

Enterprise-level mobile solution based on Vant