File tree Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change 22
22
<div v-else >
23
23
<p >No reviews have been added for this product.</p >
24
24
</div >
25
+
26
+ <h3 >Add Review</h3 >
27
+
28
+ <form @submit.prevent =" addNewReview(newReview)" >
29
+ <div class =" form-group" >
30
+ <label for =" reviewName" >Name</label >
31
+ <input type =" text" v-model =" newReview.reviewer" class =" form-control" id =" reviewName" placeholder =" Name" >
32
+ </div >
33
+
34
+ <div class =" form-group" >
35
+ <label for =" reviewRating" >Rating</label >
36
+ <input type =" number" v-model.number =" newReview.rating" class =" form-control" id =" reviewRating" placeholder =" Rating" >
37
+ </div >
38
+
39
+ <div class =" form-group" >
40
+ <label for =" reviewText" >Text</label >
41
+ <textarea v-model =" newReview.text" class =" form-control" id =" reviewText" cols =" 30" rows =" 10" ></textarea >
42
+ </div >
43
+
44
+ <button type =" submit" class =" btn btn-primary" >Submit Review</button >
45
+ </form >
25
46
</div >
26
47
27
48
<div v-else >
39
60
},
40
61
data () {
41
62
return {
42
- product: null
63
+ product: null ,
64
+ newReview: {
65
+ text: ' ' ,
66
+ rating: 0 ,
67
+ reviewer: ' '
68
+ }
43
69
};
44
70
},
45
71
created () {
65
91
},
66
92
goBack () {
67
93
this .$router .history .go (- 1 );
94
+ },
95
+ addNewReview (review ) {
96
+ this .$http .post (' http://localhost:3000/products/{productId}/reviews' , review, {
97
+ params: {
98
+ productId: this .product .id
99
+ }
100
+ }).then (
101
+ response => response .json (),
102
+ response => alert (" Could not add review!" )
103
+ ).then (newReview => this .product .reviews .push (newReview));
68
104
}
69
105
}
70
106
}
You can’t perform that action at this time.
0 commit comments