0

How I use the following code in vuejs using v-for?

@php $rating = 3; @endphp

@foreach(range(1,5) as $r)
<span class="fa-stack" style="width:1em">
    <i class="far fa-star fa-stack-1x"></i>

    @if($rating >0)
        @if($rating >0.5)
          <i class="fas fa-star fa-stack-1x"></i>
        @else
          <i class="fas fa-star-half fa-stack-1x"></i>
        @endif
    @endif

    @php $rating--; @endphp
</span>
@endforeach

I used following method. But I have no idea how I decrement rating.

<span class="fa-stack" style="width:1em" v-for="r in 5">
    <i class="far fa-star fa-stack-1x"></i>
    <i class="fas fa-star fa-stack-1x" v-if="product.average_rating > 0  && product.average_rating > 0.5"></i>
    <i class="fas fa-star-half fa-stack-1x" v-if="product.average_rating > 0  && !(product.average_rating > 0.5)"></i>
</span>
1
  • Migrating laravel template using vuejs Commented Mar 28, 2019 at 12:57

1 Answer 1

1

I don't think you can do in the same way as in blade, but if it is product.average_rating that you want to decrement, then you could replace product.average_rating with (product.average_rating - r + 1) everywhere in the code block you provided. Like this:

<span class="fa-stack" style="width:1em" v-for="r in 5">
    <i class="far fa-star fa-stack-1x"></i>
    <i class="fas fa-star fa-stack-1x" v-if="(product.average_rating - r + 1) > 0  && (product.average_rating - r + 1) > 0.5"></i>
    <i class="fas fa-star-half fa-stack-1x" v-if="(product.average_rating - r + 1) > 0  && !((product.average_rating - r + 1) > 0.5)"></i>
</span>
Sign up to request clarification or add additional context in comments.

2 Comments

can you provide an example?
@UttaraInfoTech updated my answer with the example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.