uniapp实现的简约美观的星级评分组件

采用 uniapp 实现的一款简约美观的星级评分模板,提供丝滑动画效果,用户可根据自身需求进行自定义修改、扩展,纯CSS、HTML实现,支持web、H5、微信小程序(其他小程序请自行测试)

可到插件市场下载尝试: https://ext.dcloud.net.cn/plugin?id=23736

  • 示例
    • 微信小程序端效果

    • H5端效果

props 属性

selectedStar

默认值选中星级

js 复制代码
selectedStar: {
    type: number,
    default: 0,
},

level

最高等级

js 复制代码
level: {
    type: number,
    default: 5,
},

事件

@change

点击星级变化时触发

使用示例

vue2 写法

js 复制代码
<template>
	<view style="padding: 10rpx; display: flex; flex-direction: column;row-gap: 40rpx;">
		<view style="display: flex; flex: auto;">
			<StarRating :selected-star="2" :level="3" @change="onChange"></StarRating>
		</view>
		<view style="display: flex; flex: auto;">
			<StarRating :selected-star="1" :level="5"></StarRating>
		</view>
		<view style="display: flex; flex: auto;">
			<StarRating :selected-star="5" :level="8"></StarRating>
		</view>
	</view>
</template>


<script>
import StarRating from './comp/star-rating.vue';
export default {
	components: {
		StarRating
	},
	data() {
		return {

		}
	},
	methods: {
		onChange(value) {
			console.log('Selected star rating:', value);
		}
	}
}
</script>

<style scoped></style>

vue3 写法

js 复制代码
<template>
	<view style="padding: 10rpx; display: flex; flex-direction: column; row-gap: 40rpx;">
		<view style="display: flex; flex: auto;">
			<StarRating :selected-star="2" :level="3" @change="onChange" />
		</view>
		<view style="display: flex; flex: auto;">
			<StarRating :selected-star="1" :level="5" />
		</view>
		<view style="display: flex; flex: auto;">
			<StarRating :selected-star="5" :level="8" />
		</view>
	</view>
</template>

<script setup>
import StarRating from './comp/star-rating.vue';

function onChange(value) {
	console.log('Selected star rating:', value);
}
</script>

<style scoped></style>
相关推荐
0思必得011 分钟前
[Web自动化] Selenium处理Cookie
前端·爬虫·python·selenium·自动化
2501_9159184114 分钟前
中小团队发布,跨平台 iOS 上架,证书、描述文件创建管理,测试分发一体化方案
android·ios·小程序·https·uni-app·iphone·webview
徐同保20 分钟前
react-markdown使用
前端·react.js·前端框架
2601_9498574328 分钟前
Flutter for OpenHarmony Web开发助手App实战:CSS参考
前端·css·flutter
无法长大28 分钟前
如何判断项目需不需要用、能不能用Tailwind CSS
前端·css·vue.js·elementui·vue3·tailwind css
橙露30 分钟前
移动端前端适配:Rem、VW/VH 与媒体查询的综合应用指南
前端·媒体
IT北辰38 分钟前
基于Vue3+python+mysql8.0的财务凭证录入系统,前后端分离完整版(可赠送源码)
python·vue
家里有只小肥猫44 分钟前
uniApp打包ios报错
ios·uni-app
GGGG寄了1 小时前
CSS——CSS引入方式+选择器类型
前端·css·html
墨染青竹梦悠然1 小时前
基于Django+vue的图书借阅管理系统
前端·vue.js·后端·python·django·毕业设计·毕设