Rate 评分

该组件目前处于实验性状态,需要进行更加严密的测试,API 也可能发生比较大的变动

用来选中星级

import { DuRate } from 'dangoui'

示例

基本用法
<template>
  <PreviewBlock title="不同大小" >
    <div>
      <DuRate
        size="large"
        :count="7"
        :value="5.3"
      />
      <DuRate
        size="medium"
      />
      <DuRate
        size="small"
      />
      <DuRate
        size="mini"
      />
    </div>
  </PreviewBlock>
  <PreviewBlock title="改变值" >
    <DuRate
      size="medium"
      :value="value"
      @update:value="handleUpdate"
    />
  </PreviewBlock>
  <PreviewBlock title="动画效果 - bounce">
    <DuRate
      size="large"
      animation="bounce"
      :defaultValue="3"
    />
  </PreviewBlock>
  <PreviewBlock title="从 dangoui-icon-config 导入图标,推荐用这个" >
    <DuRate
      size="large"
      :defaultValue="3.7"
      :icon="iconLikeNormal"
    />
  </PreviewBlock>
  <PreviewBlock title="自定义图标" >
    <DuRate
      size="large"
      :defaultValue="3.7"
      icon="like-normal"
    />
  </PreviewBlock>
    <PreviewBlock title="支持半选" >
    <DuRate
      size="large"
      v-model:value="percentValue"
      icon="like-normal"
      half
    />
  </PreviewBlock>
  <PreviewBlock title="带文字" >
    <DuRate
      size="large"
      icon="like-normal"
      half
      withText
      :text-list="[ '丑', '难看', '还行', '不错', '绝美']"
      :defaultValue="3"
    />
  </PreviewBlock>
   <PreviewBlock title="非受控" >
    <DuRate
      size="large"
      icon="like-normal"
      half
      defaultValue="3"
    />
  </PreviewBlock>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import { DuRate, DuIcon } from 'dangoui'
import { iconLikeNormal } from 'dangoui-icon-config'

const value = ref(1.5)
const percentValue = ref(1.5)

watch(percentValue, (v) => {
  console.log(v)
})

function handleUpdate(v: number) {
  value.value = v
}

</script>
0
不同颜色
<template>
  <PreviewBlock title="primary">
    <DuRate :value="4" color="primary" />
  </PreviewBlock>
  <PreviewBlock title="secondary">
    <DuRate :value="4" color="secondary" />
  </PreviewBlock>
  <PreviewBlock title="success">
    <DuRate :value="4" color="success" />
  </PreviewBlock>
  <PreviewBlock title="warning">
    <DuRate :value="4" color="warning" />
  </PreviewBlock>
  <PreviewBlock title="error">
    <DuRate :value="4" color="error" />
  </PreviewBlock>
  <PreviewBlock title="trade">
    <DuRate :value="4" color="trade" />
  </PreviewBlock>
  <PreviewBlock title="使用 hex 色值">
    <DuRate :value="4" color="#666" />
  </PreviewBlock>
</template>

<script setup lang="ts">
import { DuRate } from 'dangoui'
</script>
0

API

属性

属性名类型默认值说明
colorstring"#FC7E22"主题颜色
valuenumber - 当前值
ext-classstring | string[] | Record<string, boolean>""
ext-stylestring | { [x: string]: string | number; }""
size"normal" | "mini" | "small" | "medium" | "large""medium"Rate 组件尺寸
iconstring | { _: string; }iconRateFilled图标,对应 icon 组件的 name
disabledbooleanfalse是否禁用评分
animation"bounce" | "fade" | nullnull评分改变时触发的过渡动画
countnumber5总数
default-valuenumber0默认值
clickablebooleantrue是否禁用评分
halfbooleanfalse是否支持半选
with-textbooleanfalse是否在icon下显示文字,该项只在size为large的情况下可用
text-liststring[] - 文字列表

事件

名称类型
update:value(event: "update:value", i: number): void
change(event: "change", value: { value: number | undefined; }): void
本页包含