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 小时前
基础入门 React Native 鸿蒙跨平台开发:颜色选择器工具
react native·react.js·harmonyos
不爱吃糖的程序媛18 小时前
Flutter-OH生态再升级:兼容库数量翻倍,全面支持Flutter 3.27,聚焦开发者体验
华为·harmonyos
摘星编程18 小时前
OpenHarmony环境下React Native:Easing.bounce弹跳效果
react native·华为·harmonyos
猛扇赵四那边好嘴.18 小时前
Flutter 框架跨平台鸿蒙开发 - 书籍借阅管理器应用开发教程
flutter·华为·harmonyos
夜雨声烦丿18 小时前
Flutter 框架跨平台鸿蒙开发 - 日期计算器应用开发教程
flutter·华为·harmonyos
小雨青年19 小时前
鸿蒙 HarmonyOS 6 | 系统能力 (02):文件管理基石 应用沙箱机制与文件 IO 深度解析
华为·harmonyos
AI_零食19 小时前
鸿蒙的flutter框架表达:生命律动系统
学习·flutter·ui·华为·harmonyos·鸿蒙
大雷神19 小时前
HarmonyOS智慧农业管理应用开发教程--高高种地---第4篇:引导流程与用户画像
华为·harmonyos
zhujian8263719 小时前
二十八、【鸿蒙 NEXT】orm框架
数据库·华为·sqlite·harmonyos·orm框架
AI_零食19 小时前
鸿蒙跨端框架 Flutter 学习 Day 6:Future 在 UI 渲染中的心跳逻辑
学习·flutter·ui·华为·harmonyos·鸿蒙