mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
3.0 KiB
3.0 KiB
Rate
Intro
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 void-icon="star" void-color="#eee" />
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 />
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
Attribute | Description | Type | Default |
---|---|---|---|
v-model | Current rate | number | - |
count | Count | number | string | 5 |
size | Icon size | number | string | 20px |
gutter | Icon gutter | number | string | 4px |
color | Selected color | string | #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 |
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
Event | Description | Parameters |
---|---|---|
change | Emitted when rate changed | current rate |
Less Variables
How to use: Custom Theme.
Name | Default Value | Description |
---|---|---|
@rate-icon-size | 20px |
- |
@rate-icon-gutter | @padding-base |
- |
@rate-icon-void-color | @gray-5 |
- |
@rate-icon-full-color | @red |
- |
@rate-icon-disabled-color | @gray-5 |
- |