Use KtComment
to display a comment thread, a comment post and
comment replies. It allows adding new replies by clicking on the
Reply
button.
Use KtCommentInput
to input new comment posts.
Example
Settings
Texts
<KtComment
v-for="comment in comments"
:key="comment.id"
v-bind="comment"
allowInternal
dataTest="comments"
:isReadOnly="false"
:tabIndex="1"
:userAvatar="currentUser.avatar"
@add="handleAdd($event)"
@delete="handleDelete($event)"
@edit="handleEdit($event)"
/>
<KtCommentInput
allowInternal
dataTest="comments"
placeholder="Add a comment"
:tabIndex="1"
:userAvatar="currentUser.avatar"
@add="handleAdd($event)"
/>
Usage
Comment Object
{
createdAt: '2018-12-04 09:57',
id: 1,
isDeletable: true,
isEditable: true,
isInternal: true,
isModified: true,
message: 'Comment message',
replies: [
{
createdAt: '2018-12-04 09:57',
id: 2,
isDeletable: false,
isEditable: false,
isInternal: true,
isModified: true,
message: 'Reply message',
user: {
avatar: 'https://picsum.photos/200',
id: 102,
name: 'User name',
},
},
],
user: {
avatar: 'https://picsum.photos/230',
id: 101,
name: 'User name',
},
}
Events
Event Name | Component | Payload | Description |
---|---|---|---|
@add | KtComment , KtCommentInput |
| Add new comment |
@delete | KtComment |
| Delete comment |
@edit | KtComment |
| Edit comment |
Parsing HTML
KtComment will escape all tags by default but you can opt out and pass your own parser by using the parser prop.
Remember to escape malicious tags to prevent Cross-site-scripting attacks, you can use KtComment's default parser function with KtComment.defaultParser.
methods: {
dangerouslyOverrideParser: msg => escape(msg).replace(/\n/g, '<br />'),
// alternativly you could
dangerouslyOverrideParser: msg => escape(msg),
postEscapeParser: msg => msg.replace(/\n/g, '<br />'),
// or just
postEscapeParser: msg => msg.replace(/\n/g, '<br />'),
}