手册版本 V3.0
组件名称
graceStar : /graceUI/组件目录/graceStar
组件属性
// 图标大小 单位 rpx
fontSize : { type : String, default : "50rpx"},
// 星级数量
totalstars : { type : Number, default : 5},
// 选中的星级数量
starnum : { type : Number, default : 0},
// 默认颜色
color : { type : String, default : '#A5A7B2'},
// 激活颜色
activecolor :{ type : String, default : '#F5C359'},
// 是否可以被点击
cantap : { type : Boolean, default : true}更改图标
组件使用字体展示了星标,您可以扩展字体实现自己的星级图标;
演示代码
UNI 普通版本
NVUE 版本
微信小程序独立版本
<template>
<gracePage :customHeader="false">
<view slot="gBody" class="grace-body">
<view class="grace-margin-top">
<text class="grace-title">静态星标</text>
</view>
<view style="width:250rpx; margin:0 auto;">
<graceStar :starnum="currentStarNum1" :cantap="false"></graceStar>
</view>
<view class="grace-margin-top">
<text class="grace-title">可变星标</text>
</view>
<view style="width:480rpx; margin:0 auto">
<graceStar :starnum="currentStarNum2" :totalstars="8" activecolor="#E76B61" fontSize="60rpx" v-on:starchange="starchange"></graceStar>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceStar from '../../graceUI/components/graceStar.vue';
export default {
data() {
return {
currentStarNum1 : 1,
currentStarNum2 : 3
}
},
onLoad : function(){
// 延迟模拟网络请求改变星标
setTimeout(function(){
this.currentStarNum1 = 4;
}.bind(this), 1000);
},
methods:{
starchange: function (e) {
console.log(JSON.stringify(e));
this.currentStarNum2 = e;
uni.showToast({
title: e + "星",
icon:"none"
})
}
},
components:{
gracePage, graceStar
}
}
</script>
<style>
</style>
<template>
<gracePage :customHeader="false">
<view slot="gBody" class="grace-body">
<view class="grace-margin-top">
<text class="grace-title">静态星标</text>
</view>
<view style="width:250rpx; margin:0 auto;">
<graceStar :starnum="currentStarNum1" :cantap="false"></graceStar>
</view>
<view class="grace-margin-top">
<text class="grace-title">可变星标</text>
</view>
<view style="width:480rpx; margin:0 auto">
<graceStar :starnum="currentStarNum2" :totalstars="8" activecolor="#E76B61" fontSize="60rpx" v-on:starchange="starchange"></graceStar>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceStar from '../../graceUI/weexComponents/graceStar.nvue';
export default {
data() {
return {
currentStarNum1 : 1,
currentStarNum2 : 3
}
},
onLoad : function(){
// 延迟模拟网络请求改变星标
setTimeout(function(){
this.currentStarNum1 = 4;
}.bind(this), 1000);
},
methods:{
starchange: function (e) {
console.log(JSON.stringify(e));
this.currentStarNum2 = e;
uni.showToast({
title: e + "星",
icon:"none"
})
}
},
components:{
gracePage, graceStar
}
}
</script>
<style>
</style>
.wxml
<gracePage customHeader="{{false}}">
<view slot="gBody" class="grace-body">
<view class="grace-margin-top">
<text class="grace-title">静态星标</text>
</view>
<view style="width:250rpx; margin:0 auto;">
<graceStar starnum="{{currentStarNum1}}" cantap="{{false}}"></graceStar>
</view>
<view class="grace-margin-top">
<text class="grace-title">可变星标</text>
</view>
<view style="width:480rpx; margin:0 auto">
<graceStar starnum="{{currentStarNum2}}" totalstars="{{8}}" activecolor="#E76B61" fontSize="60rpx" bind:starChange="starchange"></graceStar>
</view>
</view>
</gracePage>.js
Page({
data: {
currentStarNum1: 1,
currentStarNum2: 3
},
onLoad : function(){
// 延迟模拟网络请求改变星标
setTimeout(() => {
this.setData({currentStarNum1 : 4});
}, 1000);
},
starchange : function (e) {
this.setData({ currentStarNum2: e.detail});
wx.showToast({
title: e.detail + "星",
icon: "none"
})
}
});.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage",
"graceStar": "../../graceUI/components/graceStar"
}
}