File tree Expand file tree Collapse file tree 2 files changed +47
-39
lines changed Expand file tree Collapse file tree 2 files changed +47
-39
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div class =" col-md-8 form-group mb-0" >
3
+ <template v-if =" isEditing " >
4
+ <textarea
5
+ class =" form-control"
6
+ rows =" 3"
7
+ placeholder =" Did you like this movie?"
8
+ v-model =" comment"
9
+ ></textarea >
10
+ <div :class =" [commentWordCount > 0 ? 'text-success' : 'text-danger']" >
11
+ {{ commentWordCount }} word{{ commentWordCount !== 1 ? 's' : '' }}
12
+ </div >
13
+ </template >
14
+ <div v-else v-html =" formattedComment" />
15
+ <button class =" btn btn-primary mt-2" @click =" isEditing = !isEditing" >
16
+ {{ isEditing ? 'Save comment' : 'Edit comment' }}
17
+ </button >
18
+ </div >
19
+ </template >
20
+
21
+ <script >
22
+ export default {
23
+ name: ' movie-comment' ,
24
+ data () {
25
+ return {
26
+ comment: ' ' ,
27
+ isEditing: false ,
28
+ };
29
+ },
30
+ computed: {
31
+ commentWordCount () {
32
+ return this .comment .split (/ \s + / ).filter (word => word !== ' ' ).length ;
33
+ },
34
+ formattedComment () {
35
+ if (! this .commentWordCount ) {
36
+ return ' No comment yet.' ;
37
+ }
38
+ return ` Your comment: <b>${ this .comment } </b>` ;
39
+ },
40
+ },
41
+ };
42
+ </script >
Original file line number Diff line number Diff line change 16
16
</div >
17
17
</div >
18
18
<div class =" row mt-4" >
19
- <div class =" col-md-8 form-group mb-0" >
20
- <template v-if =" isEditing " >
21
- <textarea
22
- class =" form-control"
23
- rows =" 3"
24
- placeholder =" Did you like this movie?"
25
- v-model =" item.comment"
26
- ></textarea >
27
- <div
28
- :class =" [commentWordCount > 0 ? 'text-success' : 'text-danger']"
29
- >
30
- {{ commentWordCount }} word{{
31
- commentWordCount !== 1 ? 's' : ''
32
- }}
33
- </div >
34
- </template >
35
- <div v-else v-html =" formattedComment" />
36
- <button
37
- class =" btn btn-primary mt-2"
38
- @click =" isEditing = !isEditing"
39
- >
40
- {{ isEditing ? 'Save comment' : 'Edit comment' }}
41
- </button >
42
- </div >
19
+ <movie-comment />
43
20
</div >
44
21
</div >
45
22
</div >
46
23
</div >
47
24
</template >
48
25
49
26
<script >
27
+ import MovieComment from ' ./MovieComment.vue' ;
28
+
50
29
export default {
51
30
name: ' movie-item' ,
52
- data () {
53
- return {
54
- isEditing: false ,
55
- };
31
+ components: {
32
+ MovieComment,
56
33
},
57
34
props: {
58
35
item: {
59
36
type: Object ,
60
37
required: true ,
61
38
},
62
39
},
63
- computed: {
64
- commentWordCount () {
65
- return this .item .comment .split (/ \s + / ).filter (word => word !== ' ' ).length ;
66
- },
67
- formattedComment () {
68
- if (! this .commentWordCount ) {
69
- return ' No comment yet.' ;
70
- }
71
- return ` Your comment: <b>${ this .item .comment } </b>` ;
72
- },
73
- },
74
40
};
75
41
</script >
You can’t perform that action at this time.
0 commit comments