Skip to content

Commit 05e9580

Browse files
author
Patrick Dolega
committed
Merge branch 'master' of https://github.com/patosz/Vue.js-Tutorial into master2
2 parents 08d8d21 + 56a4aa4 commit 05e9580

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: cli-socks/src/components/Product.vue

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<i v-for="i in averageReviewScore" class="fa fa-star" :key="i"></i>
1212
</h1>
1313

14-
<div>All reviews:</div>
14+
<div v-if="product.reviews.length">All reviews:</div>
1515
<div v-for="j in product.reviews" :key="j.name+j.rating">
1616
<label>{{ j.name}}: </label>
1717
<i v-for="k in j.rating" class="fa fa-star" :key="k"></i>
@@ -67,7 +67,7 @@ import ProductReview from './ProductReview.vue';
6767
6868
export default class Product extends Vue {
6969
@Prop({default: false}) private premium!: boolean;
70-
@Prop() private cartLength: number;
70+
@Prop() private cartLength!: number;
7171
7272
product = {
7373
name: "Vue Socks",
@@ -91,7 +91,12 @@ export default class Product extends Vue {
9191
if (!this.product.reviews.length) {
9292
return null;
9393
}
94-
return Math.round(this.product.reviews.map(x => x.rating).reduce((a, c) => a + c, 0) / this.product.reviews.length);
94+
const reviews = this.product.reviews as any;
95+
const totalStars = reviews
96+
.map((x: any) => x.rating)
97+
.reduce((a: any, c: any) => a + c, 0);
98+
99+
return Math.round(totalStars / this.product.reviews.length);
95100
}
96101
97102
get title() {

0 commit comments

Comments
 (0)