vue3 | vue-star-rating插件 | 五星评分插件 | 精度为0.01

371 阅读2分钟

官网:www.npmjs.com/package/vue…

image.png

效果图

屏幕录制2024-08-25 13.04.54_converted.gif

demo集合 codepen.io/craigh411/p…

安装

npm install vue-star-rating@next

General Props

These props provide general functionailty to the star rating component

PropDescriptionTypeDefault
incrementThe rating increment, for example pass 0.5 for half stars or 0.01 for fluid stars. Expects a number between 0.01 - 1.Number1
ratingThe initial rating, this will automatically round to the closest increment, so for the most accurate rating pass 0.01 as increment or set the round-start-rating prop to falseNumber0
max-ratingThe maximum rating, this lets vue-star-rating know how many stars to displayNumber5
star-pointsThe points defining a custom star shape. If no points are passed the default star shape is used.Array[]
read-onlyWhen set to true, the rating cannot be edited. Use in conjuction with increment to define rounding precision.Booleanfalse
show-ratingWhether or not to show the rating next to the starsBooleantrue
fixed-pointsSpecify a fixed number of digits after the decimal point.Numbernull
rtlPass true to display star rating using rtl (right-to-left)Booleanfalse
round-start-ratingPass false if you don't want the start rating value to round to the closest increment. The user will still only be able to select based on the given increment.Booleantrue
clearableWhen set to true a second click on the same rating clears the ratingBooleanfalse
active-on-clickWhen set to true only apply active colors when the user clicks the star, rather than on mouseover.Booleanfalse

Style Props

These props are used to style the star rating component

PropDescriptionTypeDefault
star-sizeThe size of each star, this gets passed to the SVG width attribute, so larger numbers are larger starsNumber50
inactive-colorThe color of the non-highlighted portion of a star.String#d8d8d8
active-colorThe color of the highlighted portion of a star. Pass an array of colors to color each star individuallyStringArray#ffd055
border-colorSets the colour of the border for each starString#999
active-border-colorThe border color of a highlighted star. Pass an array of colors to color each star's border individuallyStringArraynull
border-widthSets the width of the border for each starNumber0
animateSet to true for an animation to be applied on mouseoverBooleanfalse
paddingPads the right of each star so distance between stars can be alteredNumber0
rounded-cornersWhether or not to round the star's cornersBooleanfalse
inlineSets the star rating to display inlineBooleanfalse
glowAdds a subtle glow around each active star, this should be a number to spread the glowNumber0
glow-colorSets the color for the glowString#fff
text-classA css class name to style the rating text for a specific star rating componentString''

Important:  Vue requires you to pass numbers and boolean values using v-bind, any props that require a number or bool should use v-bind: or the colon (:) shorthand.

Props Example

<star-rating v-bind:increment="0.5"
             v-bind:max-rating="3"
             inactive-color="#000"
             active-color="#f00"
             v-bind:star-size="90">
</star-rating>