We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
quickApp ReferencesQuick AppElementsrating

rating

Overview

Shows a star rating to the user.

Application Scope

Expand

Item

Description

Applicable devices

Mobile phones, tablets, Vision products, and telematics devices

Applicable regions

Global

Subelements

None

Attributes

In addition to general attributes, the attributes listed in the following table are supported.

Expand

Attribute

Type

Default Value

Mandatory

Description

numstars

number

5

No

Number of stars to be displayed on a rating bar.

rating

number

0

No

Number of selected stars.

stepsize

number

0.5

No

Step size of the rating.

indicator

boolean

false

No

Indicates whether to make a rating icon as only an indicator (not-editable by the user).

Styles

The active pseudo-class is supported. In addition to common styles, the styles listed in the following table are supported.

Expand

Style

Type

Default Value

Mandatory

Description

star-background

uri

-

No

Only images specified by a local path or Base64-encoded image are supported. It is an exclusive extension for quick apps to be used on Huawei phones, and is not a part of the quick app specifications formulated by the vendor alliance.

star-foreground

uri

-

No

Only images specified by a local path or Base64-encoded image are supported. It is an exclusive extension for quick apps to be used on Huawei phones, and is not a part of the quick app specifications formulated by the vendor alliance.

star-secondary

uri

-

No

Only images specified by a local path or Base64-encoded image are supported. It is an exclusive extension for quick apps to be used on Huawei phones, and is not a part of the quick app specifications formulated by the vendor alliance.

width

length|percentage

Value of numstars x Width of a star

No

The default value is the value of numstars multiplied by the width of a star.

height

length|percentage

Height of a star.

No

Its default value is the height of a star.

Events

The click, longpress, and swipe events are not supported. In addition to common events, the event listed in the following table is supported.

Expand

Event

Parameter

Triggering Condition

change

{rating:currentRating, isFromUser:isFromUserValue 1080+}

The rating value changes.

isFromUser: indicates whether the event is triggered by a user's dragging.

Sample Code

Collapse
Word wrap
Dark theme
Copy code
  1. <template>
  2. <div class="container">
  3. <div class="page-title-wrap">
  4. <text class="page-title">{{componentName}}</text>
  5. </div>
  6. <rating class="ratingStyle" numstars="4" rating="2" @change="showChangePrompt"></rating>
  7. </div>
  8. </template>
  9. <style>
  10. .container {
  11. flex: 1;
  12. flex-direction: column;
  13. }
  14. .page-title-wrap {
  15. padding-top: 50px;
  16. padding-bottom: 80px;
  17. justify-content: center;
  18. }
  19. .page-title {
  20. padding-top: 30px;
  21. padding-bottom: 30px;
  22. padding-left: 40px;
  23. padding-right: 40px;
  24. border-color: #bbbbbb;
  25. color: #bbbbbb;
  26. border-bottom-width: 2px;
  27. }
  28. .ratingStyle {
  29. star-background: url(/Common/img/ic_stars_gray_mid.png);
  30. star-foreground: url(/Common/img/ic_stars_blue_mid.png);
  31. star-secondary: url(/Common/img/ic_stars_blue_half_mid.png);
  32. height: 150px;
  33. }
  34. </style>
  35. <script>
  36. import prompt from '@system.prompt'
  37. export default {
  38. data: {
  39. componentName: 'rating'
  40. },
  41. onInit() {
  42. this.$page.setTitleBar({ text: 'rating' })
  43. },
  44. showChangePrompt(ret) {
  45. prompt.showToast({
  46. message: JSON.stringify(ret.rating)
  47. })
  48. }
  49. }
  50. </script>

The following figure shows the final effect.

Version Change History

Expand

Version

Date

Description

1080

2021-12-28

Added the isFromUser parameter, which indicates whether the current event is triggered by a user's dragging.

1010

2018-04-20

Added the support for the active pseudo-class.