index.vue
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<div>
<div class="ant-result-title">项目名称</div>
<a-list
v-if="comments.length"
:data-source="comments"
:header="`${comments.length} ${
comments.length > 1 ? 'replies' : 'reply'
}`"
item-layout="horizontal"
>
<a-list-item slot="renderItem" slot-scope="item">
<a-comment
:author="item.author"
:avatar="item.avatar"
:content="item.content"
:datetime="item.datetime"
/>
</a-list-item>
</a-list>
<a-comment>
<a-avatar
slot="avatar"
src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
alt="Han Solo"
/>
<div slot="content">
<a-form-item>
<a-textarea :rows="4" :value="value" @change="handleChange" />
</a-form-item>
<a-form-item>
<a-button
html-type="submit"
:loading="submitting"
type="primary"
@click="handleSubmit"
>
Add Comment
</a-button>
</a-form-item>
</div>
</a-comment>
</div>
</template>
<script>
import moment from "moment";
import FormItem from "ant-design-vue/lib/form/FormItem";
export default {
data() {
return {
comments: [],
submitting: false,
value: "",
moment,
};
},
components: { [FormItem.name]: FormItem },
methods: {
handleSubmit() {
if (!this.value) {
return;
}
this.submitting = true;
setTimeout(() => {
this.submitting = false;
this.comments = [
{
author: "Han Solo",
avatar:
"https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png",
content: this.value,
datetime: moment().fromNow(),
},
...this.comments,
];
this.value = "";
}, 1000);
},
handleChange(e) {
this.value = e.target.value;
},
},
};
</script>
<style>
.ant-result-title {
margin-bottom: 50px;
color: rgba(0, 0, 0, 0.85);
font-size: 24px;
line-height: 1.8;
text-align: center;
}
</style>