|
1 |
| -<template> |
2 |
| - <div> |
3 |
| - <h1>Movie Review</h1> |
4 |
| - <form @submit.prevent="submit"> |
5 |
| - <label for="movie-input">Title of the movie</label> |
6 |
| - <input id="movie-input" v-model="title" name="title" /> |
7 |
| - |
8 |
| - <label id="review-textarea">Your review</label> |
9 |
| - <textarea |
10 |
| - v-model="review" |
11 |
| - name="review-textarea" |
12 |
| - placeholder="Write an awesome review" |
13 |
| - aria-labelledby="review-textarea" |
14 |
| - /> |
15 |
| - |
16 |
| - <label> |
17 |
| - <input v-model="rating" type="radio" value="3" /> |
18 |
| - Wonderful |
19 |
| - </label> |
20 |
| - <label> |
21 |
| - <input v-model="rating" type="radio" value="2" /> |
22 |
| - Average |
23 |
| - </label> |
24 |
| - <label> |
25 |
| - <input v-model="rating" type="radio" value="1" /> |
26 |
| - Awful |
27 |
| - </label> |
28 |
| - |
29 |
| - <label id="recommend-label">Would you recommend this movie?</label> |
30 |
| - <input |
31 |
| - id="recommend" |
32 |
| - v-model="recommend" |
33 |
| - type="checkbox" |
34 |
| - name="recommend" |
35 |
| - /> |
36 |
| - |
37 |
| - <button :disabled="submitDisabled" type="submit"> |
38 |
| - Submit |
39 |
| - </button> |
40 |
| - </form> |
41 |
| - </div> |
42 |
| -</template> |
43 |
| - |
44 |
| -<script> |
45 |
| -export default { |
46 |
| - data() { |
47 |
| - return { |
48 |
| - title: '', |
49 |
| - review: '', |
50 |
| - rating: '1', |
51 |
| - recommend: false, |
52 |
| - } |
53 |
| - }, |
54 |
| - computed: { |
55 |
| - submitDisabled() { |
56 |
| - return !this.title || !this.review |
57 |
| - }, |
58 |
| - }, |
59 |
| -
|
60 |
| - methods: { |
61 |
| - submit() { |
62 |
| - if (this.submitDisabled) return |
63 |
| -
|
64 |
| - this.$emit('submit', { |
65 |
| - title: this.title, |
66 |
| - review: this.review, |
67 |
| - rating: this.rating, |
68 |
| - recommend: this.recommend, |
69 |
| - }) |
70 |
| - }, |
71 |
| - }, |
72 |
| -} |
73 |
| -</script> |
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <h1>Movie Review</h1> |
| 4 | + <form> |
| 5 | + <label for="movie-input">Title of the movie</label> |
| 6 | + <input id="movie-input" v-model="title" name="title" /> |
| 7 | + |
| 8 | + <label id="review-textarea">Your review</label> |
| 9 | + <textarea |
| 10 | + v-model="review" |
| 11 | + name="review-textarea" |
| 12 | + placeholder="Write an awesome review" |
| 13 | + aria-labelledby="review-textarea" |
| 14 | + /> |
| 15 | + |
| 16 | + <label> |
| 17 | + <input v-model="rating" type="radio" value="3" /> |
| 18 | + Wonderful |
| 19 | + </label> |
| 20 | + <label> |
| 21 | + <input v-model="rating" type="radio" value="2" /> |
| 22 | + Average |
| 23 | + </label> |
| 24 | + <label> |
| 25 | + <input v-model="rating" type="radio" value="1" /> |
| 26 | + Awful |
| 27 | + </label> |
| 28 | + |
| 29 | + <label id="recommend-label">Would you recommend this movie?</label> |
| 30 | + <input |
| 31 | + id="recommend" |
| 32 | + v-model="recommend" |
| 33 | + type="checkbox" |
| 34 | + name="recommend" |
| 35 | + /> |
| 36 | + |
| 37 | + <button :disabled="submitDisabled" type="submit" @click="submit"> |
| 38 | + Submit |
| 39 | + </button> |
| 40 | + </form> |
| 41 | + </div> |
| 42 | +</template> |
| 43 | + |
| 44 | +<script> |
| 45 | +export default { |
| 46 | + data() { |
| 47 | + return { |
| 48 | + title: '', |
| 49 | + review: '', |
| 50 | + rating: '1', |
| 51 | + recommend: false, |
| 52 | + } |
| 53 | + }, |
| 54 | + computed: { |
| 55 | + submitDisabled() { |
| 56 | + return !this.title || !this.review |
| 57 | + }, |
| 58 | + }, |
| 59 | +
|
| 60 | + methods: { |
| 61 | + submit() { |
| 62 | + if (this.submitDisabled) return |
| 63 | +
|
| 64 | + this.$emit('submit', { |
| 65 | + title: this.title, |
| 66 | + review: this.review, |
| 67 | + rating: this.rating, |
| 68 | + recommend: this.recommend, |
| 69 | + }) |
| 70 | + }, |
| 71 | + }, |
| 72 | +} |
| 73 | +</script> |
0 commit comments