HarmonyOS Developer之五星好评

rating

rating为评分条组件,用来实现用户使用感受的衡量标准条(如:五星好评)

在pages/index目录下的hml文件中创建一个rating组件:

HTML

html 复制代码
<!-- xxx.hml -->
<div class="container">
  <rating></rating>
</div>

CSS

css 复制代码
/* xxx.css */
.container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #F1F3F5;
}
rating {
  width: 80%;
  height: 150px;
}

实现非5星好评

rating组件通过设置numstars和rating属性设置评分条的星级总数和当前评星数:

HTML:

html 复制代码
<!-- xxx.hml -->
<div class="container">
  <rating numstars="6" rating="5">
  </rating>
</div>
css 复制代码
/* xxx.css */
.container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #F1F3F5;
}
rating {
  width: 80%;
  height: 150px;
}

自定义评分样式

rating组件通过star-background、star-foreground和star-secondary属性设置单个星级未选择、选中和选中的次级背景图片:

HTML

html 复制代码
<!-- xxx.hml -->
<div class="container">
  <div style="width: 500px;height: 500px;align-items: center;justify-content: center;flex-direction: column;;">
    <rating numstars="5" rating="1" class="myrating" style="width: {{ratewidth}}; height:{{rateheight}}; star-background: {{backstar}}; star-secondary: {{secstar}};star-foreground: {{forestar}};rtl-flip: true;">
    </rating>
  </div>
</div>

CSS

css 复制代码
/* xxx.css */
.container {
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #F1F3F5;
}

JS

javascript 复制代码
// index.js
export default {
  data: {
    backstar: 'common/love.png',
    secstar: 'common/love.png',
    forestar: 'common/love1.png',
    ratewidth: '400px',
    rateheight: '150px'
  },
  onInit(){
  }
}
复制代码
说明
 - star-background、star-secondary、star-foreground属性的星级图源必须全部设置,否则默认的星级颜色为灰色,提示图源设置错误。
 - star-background、star-secondary、star-foreground属性只支持本地路径图片,图片格式为png和jpg。
相关推荐
前端不太难17 小时前
从 App 到 Agent:鸿蒙应用形态正在改变
华为·harmonyos
大雷神18 小时前
HarmonyOS APP<玩转React>开源教程六:数据模型设计与实现
react.js·harmonyos
myNameGL18 小时前
DevEco Studio链接虚拟机报错解决方法
harmonyos
大雷神19 小时前
HarmonyOS APP<玩转React>开源教程五:项目架构设计
harmonyos
深海呐1 天前
鸿蒙 Video组件的基本使用(HarmonyOS-VideoView)
华为·harmonyos·harmonyos video·harmonyos 视频播放·harmonyos 播放器·harmonyos 播放视频
是稻香啊1 天前
HarmonyOS6 ArkUI 无障碍悬停事件(onAccessibilityHover)全面解析与实战演示
华为·harmonyos·harmonyos6
前端不太难1 天前
从小项目到大型鸿蒙 App 的架构变化
架构·状态模式·harmonyos
aqi001 天前
【送书活动】《鸿蒙HarmonyOS 6:应用开发从零基础到App上线》迎新送书啦
android·华为·harmonyos·鸿蒙
Oyster382891 天前
告别“盲调”与“重编”!我写了一个鸿蒙 ArkUI 纯端侧的可视化调试神器,正式开源!
harmonyos·arkui
盐焗西兰花1 天前
鸿蒙学习实战之路-Share Kit系列(7/17)-自定义分享面板操作区
linux·学习·harmonyos