欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > HarmonyOS Developer之五星好评

HarmonyOS Developer之五星好评

2024/10/24 21:23:38 来源:https://blog.csdn.net/weixin_47988426/article/details/141163165  浏览:    关键词:HarmonyOS Developer之五星好评

rating

rating为评分条组件,用来实现用户使用感受的衡量标准条(如:五星好评)
在这里插入图片描述

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

<!-- xxx.hml -->
<div class="container"><rating></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;
}

实现非5星好评

rating组件通过设置numstars和rating属性设置评分条的星级总数和当前评星数:
在这里插入图片描述

HTML:

<!-- xxx.hml -->
<div class="container"><rating numstars="6" rating="5"></rating>
</div>
/* 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

<!-- 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

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

JS

// 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。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com