VEUI

VEUI on GitHub
Play!中文

Rating

Examples

Editable

Users can set the rating interactively.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-rating v-model="value"/>
</article>
</template>

<script>
import { Rating } from 'veui'

export default {
  components: {
    'veui-rating': Rating
  },
  data () {
    return {
      value: 4
    }
  }
}
</script>

Read-only

Set the readonly prop to true to display an existing rating.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-rating
    v-model="value"
    readonly
  />
</article>
</template>

<script>
import { Rating } from 'veui'

export default {
  components: {
    'veui-rating': Rating
  },
  data () {
    return {
      value: 4
    }
  }
}
</script>

Max rating

Set the value of the max prop to specify the maximum number of rating symbols to display.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-rating
    v-model="value"
    :max="3"
  />
</article>
</template>

<script>
import { Rating } from 'veui'

export default {
  components: {
    'veui-rating': Rating
  },
  data () {
    return {
      value: 2
    }
  }
}
</script>

Clearable

Set the clearable prop to true to allow users to clear the selected rating by clicking on it.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-rating
    v-model="value"
    clearable
  />
</article>
</template>

<script>
import { Rating } from 'veui'

export default {
  components: {
    'veui-rating': Rating
  },
  data () {
    return {
      value: 4
    }
  }
}
</script>

Labels

Set the value of the labels prop to specify the description text for each rating symbol. The label-position prop can be used to specify whether the description text is displayed inline or as a tooltip.

label-position="inline" (default)

label-position="popup"

Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <h4><code>label-position="inline"</code> (default)</h4>
    <veui-rating
      v-model="value"
      :labels="labels"
    />
  </section>
  <section>
    <h4><code>label-position="popup"</code></h4>
    <veui-rating
      v-model="value"
      :labels="labels"
      label-position="popup"
    />
  </section>
</article>
</template>

<script>
import { Rating } from 'veui'

export default {
  components: {
    'veui-rating': Rating
  },
  data () {
    return {
      value: 4,
      labels: {
        1: '非常不满意',
        2: '不满意',
        3: '一般',
        4: '满意',
        5: '非常满意'
      }
    }
  }
}
</script>

Half-star

Set the allow-half prop to true to allow half-star ratings.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-rating
    v-model="value"
    allow-half
  />
</article>
</template>

<script>
import { Rating } from 'veui'

export default {
  components: {
    'veui-rating': Rating
  },
  data () {
    return {
      value: 4
    }
  }
}
</script>

Custom symbols

Use the symbol slot to customize the symbol of each rating item.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-rating v-model="value">
    <template #symbol></template>
  </veui-rating>
</article>
</template>

<script>
import { Rating } from 'veui'

export default {
  components: {
    'veui-rating': Rating
  },
  data () {
    return {
      value: 4
    }
  }
}
</script>

API

Props

NameTypeDefaultDescription
maxnumber5The maximum number of rating items to display. Must be an integer.
valuenumber-

v-model

The selected rating score, ranging from 1 to the value of the max prop.

readonlybooleanfalseWhether the rating is in read-only mode.
clearablebooleanfalseWhether to allow clearing the selected rating.
allow-halfbooleanfalseWhether to allow half-star ratings.
labelsRecord<number, string>-The description text for each rating symbol.
label-position'inline' | 'popup''inline'The display mode of the description text. Use 'inline' for inline display and 'popup' for tooltip display.

Slots

NameDescription
symbol

The symbol area of each rating item.

Default content: Display star symbols.

NameTypeDescription
valuenumberThe rating corresponding to the current symbol.
label

The label area of each rating item.

Default content: The description text specified for each rating in labels.

NameTypeDescription
valuenumberThe rating corresponding to the current symbol.

Events

NameDescription
change

v-model

Fired when the rating state changes. The callback parameter is (value: number), where value is the current selected rating score.

Custom Styles

NameTypeDefaultDescription
--dls-rating-symbol-gap<length>-The spacing between rating items.
--dls-rating-label-spacing<length>-The spacing between the description text and the rating items.
Edit this page on GitHubEdit
© Baidu, Inc. 2024