Vue Star Rating Component

1.7.0 · active · verified Sun Apr 19

`vue-star-rating` is a highly customizable star rating component for Vue.js applications, offering extensive control over its appearance and behavior. It maintains separate versions to support both Vue 2.x (primarily version 1.6.x, which remains the default `npm install`) and Vue 3 (via version 2.x, installed using `npm install vue-star-rating@next`). The library features a wide array of customization options, including custom star shapes (`star-points`), rounded corners, individual star coloring, glow effects, and full support for RTL (right-to-left) layouts. It integrates seamlessly with Vue's `v-model` for bidirectional data binding and provides fine-grained control over initial rating rounding and increment steps. The project actively develops the Vue 3 compatible version, ensuring continued relevance and compatibility within the evolving Vue ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic usage of `vue-star-rating` with Vue 3, showcasing v-model binding for an interactive rating and a read-only display. It includes several common props like `star-size`, `increment`, `glow`, and `active-color`.

import { createApp, ref } from 'vue';
import StarRating from 'vue-star-rating';

const app = createApp({
  components: {
    StarRating
  },
  setup() {
    const currentRating = ref(3.5);
    const readOnlyRating = ref(4.2);

    const setRating = (rating) => {
      currentRating.value = rating;
      console.log('New rating:', rating);
    };

    return {
      currentRating,
      readOnlyRating,
      setRating
    };
  },
  template: `
    <div>
      <h1>Interactive Star Rating</h1>
      <star-rating
        v-model:rating="currentRating"
        :increment="0.5"
        :star-size="30"
        :show-rating="false"
        :glow="5"
        glow-color="#ffd055"
        active-color="#FFD700"
        inactive-color="#D8D8D8"
        border-color="#ccc"
        :border-width="2"
        :rounded-corners="true"
        :padding="5"
        @update:rating="setRating"
      ></star-rating>
      <p>Your current rating: {{ currentRating }}</p>

      <h2>Read-only Rating</h2>
      <star-rating
        :rating="readOnlyRating"
        :read-only="true"
        :increment="0.01"
        :star-size="25"
        :fixed-points="2"
        :show-rating="true"
        active-color="#42b883"
        inactive-color="#f0f0f0"
      ></star-rating>
      <p>Average rating: {{ readOnlyRating }}</p>
    </div>
  `
});

app.mount('#app');

view raw JSON →