File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 14
14
15
15
<div v-if =" product.reviews.length > 0" >
16
16
<div v-for =" review in product.reviews" >
17
- <strong >{{ review.reviewer }}</strong > (rating: {{ review.rating }})
17
+ <strong >{{ review.reviewer }}</strong > (rating: {{ review.rating }}) -
18
+ <a href =" #" @click.prevent =" deleteReview(review)" >delete</a >
18
19
<p >{{ review.text }}</p >
19
20
</div >
20
21
</div >
65
66
text: ' ' ,
66
67
rating: 0 ,
67
68
reviewer: ' '
68
- }
69
+ },
70
+ reviewResource: null
69
71
};
70
72
},
71
73
created () {
74
+ let url = ' http://localhost:3000/products/{productId}/reviews/{reviewId}' ;
75
+ this .reviewResource = this .$resource (url);
76
+
72
77
this .getProduct (this .productId )
73
78
.then (product => this .product = product);
74
79
},
101
106
response => response .json (),
102
107
response => alert (" Could not add review!" )
103
108
).then (newReview => this .product .reviews .push (newReview));
109
+ },
110
+ deleteReview (review ) {
111
+ this .reviewResource .delete ({
112
+ productId: this .product .id ,
113
+ reviewId: review .id
114
+ }).then (
115
+ response => {
116
+ // Just be lazy and fetch product again
117
+ this .getProduct (this .product .id )
118
+ .then (product => this .product = product);
119
+ },
120
+ response => alert (" Could not delete review!" )
121
+ );
104
122
}
105
123
}
106
124
}
You can’t perform that action at this time.
0 commit comments