当前位置: 首页 > 文档资料 > uView 开发文档 >

Rate 评分

优质
小牛编辑
118浏览
2023-12-01

Rate 评分 平台差异说明
AppH5微信小程序支付宝小程序百度小程序头条小程序QQ小程序

基本使用

  • 通过count参数设置总共有多少颗星星可选择
  • 通过v-model双向绑定初始化时默认选中的星星数量 1.4.5新增
  • 通过current设置初始化时默认选中的星星数量(1.4.5后建议使用v-model的方式,此参数为了向前兼容依然有效,但优先级低于v-model)
<template>
	<u-rate :count="count" v-model="value"></u-rate>
</template>

<script>
	export default {
		data() {
			return {
				count: 4,
				value: 2
			}
		}
	}
</script>

自定义样式

  • 通过active-color设置选中的星星的颜色
  • 通过inactive-color设置未选中时星星的颜色
  • 通过gutter设置星星的间距,左右内边距各占gutter的一半
<u-rate active-color="#FA3534" inactive-color="#b2b2b2" gutter="20"></u-rate>

自定义图标

  • 通过active-icon设置激活的图标
  • 通过inactive-icon设置未激活的图标
  • 通过custom-prefix设置自定义图标,详见:扩展自定义图标库

下方示例为使用心形图标替代默认的星星图标:

<u-rate active-icon="heart-fill" inactive-icon="heart"></u-rate>

评分分级分层 1.7.2

  • 通过colors设置不同颜色区分评分层级
  • 通过icons设置不同类型图标区分评分层级
<template>
  <view>
    <u-rate v-model="value" :colors="colors" :icons="icons" inactive-icon="thumb-up"></u-rate>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        value: 2,
        colors: ['#ffc454', '#ffb409', '#ff9500'],
        icons: ['thumb-down-fill', 'thumb-down-fill', 'thumb-up-fill', 'thumb-up-fill']
      }
    }
  }
</script>

最少选中的数量

<u-rate :min-count="5"></u-rate>

禁用状态

禁用下,无法点击或者滑动选择,但是可以通过current设置默认选中的数量,禁用状态下用来展示分数,允许出现半星

<u-rate :current="3.7" :disabled="true"></u-rate>

API

Props

参数说明类型默认值可选值
v-model 1.4.5双向绑定选择星星的数量String | Number0-
count最多可选的星星数量String | Number5-
current默认选中的星星数量,1.4.5起建议使用v-model方式String | Number0-
disabled是否禁止用户操作Booleanfalsetrue
size星星的大小,单位rpxString | Number32-
inactive-color未选中星星的颜色String#b2b2b2-
active-color选中的星星颜色String#FA3534-
gutter星星之间的距离String | Number10-
min-count最少选中星星的个数String | Number0-
active-icon选中时的图标名,只能为uView的内置图标Stringstar-fill-
inactive-icon未选中时的图标名,只能为uView的内置图标Stringstar-
custom-prefix 1.7.2自定义字体图标库时,需要写上此值,详见:扩展自定义图标库Stringuicon-
colors 1.7.2颜色分级显示,可以用不同颜色区分评分层级Array--
icons 1.7.2图标分级显示,可以用不同类型的icon区分评分层级Array--

Events

事件名说明回调参数
change选中的星星发生变化时触发value:当前选中的星星的数量,如果使用v-model双向绑定方式,无需监听此事件