import{o as a,a as t,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},l=n(`

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.

import { createApp } from 'vue';
import { Rate } from 'vant';

const app = createApp();
app.use(Rate);

Usage

Basic Usage

<van-rate v-model="value" />
import { ref } from 'vue';

export default {
  setup() {
    const value = ref(3);
    return { value };
  },
};

Custom Icon

<van-rate v-model="value" icon="like" void-icon="like-o" />

Custom Style

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

Half Star

<van-rate v-model="value" allow-half />
import { ref } from 'vue';

export default {
  setup() {
    const value = ref(2.5);
    return { value };
  },
};

Custom Count

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

Disabled

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

Readonly

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

Readonly Half Star

<van-rate v-model="value" readonly />
import { ref } from 'vue';

export default {
  setup() {
    const value = ref(3.3);
    return { value };
  },
};

Change Event

<van-rate v-model="value" @change="onChange" />
import { ref } from 'vue';
import { Toast } from 'vant';

export default {
  setup() {
    const value = ref(3);
    const onChange = (value) => Toast('current value:' + value);
    return {
      value,
      onChange,
    };
  },
};

API

Props

AttributeDescriptionTypeDefault
v-modelCurrent ratenumber-
countCountnumber | string5
sizeIcon sizenumber | string20px
gutterIcon gutternumber | string4px
colorSelected colorstring#ee0a24
void-colorVoid colorstring#c8c9cc
disabled-colorDisabled colorstring#c8c9cc
iconSelected iconstringstar
void-iconVoid iconstringstar-o
icon-prefixIcon className prefixstringvan-icon
allow-halfWhether to allow half starbooleanfalse
readonlyWhether to be readonlybooleanfalse
disabledWhether to disable ratebooleanfalse
touchableWhether to allow select rate by touch gesturebooleantrue

Events

EventDescriptionParameters
changeEmitted when rate changedcurrentValue: number

Types

The component exports the following type definitions:

import type { 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)-
`,19),d=[l],i={__name:"README",setup(c,{expose:s}){return s({frontmatter:{}}),(p,o)=>(a(),t("div",e,d))}};export{i as default};