Appearance
对网站内容的评论、讨论等。
最简单的用法,包含作者、头像、内容和时间。
<template> <YcComment author="张三" avatar="https://via.placeholder.com/40x40" content="这是一条评论内容" datetime="2024-01-15 14:30:00" /> </template>
通过插槽实现嵌套评论。
<template> <YcComment author="张三" avatar="https://via.placeholder.com/40x40" content="这是一条评论内容" datetime="2024-01-15 14:30:00" > <YcComment author="李四" avatar="https://via.placeholder.com/32x32" content="这是对张三评论的回复" datetime="2024-01-15 15:00:00" /> <YcComment author="王五" avatar="https://via.placeholder.com/32x32" content="这是另一条回复" datetime="2024-01-15 16:00:00" /> </YcComment> </template>
通过 avatar 插槽自定义头像内容。
avatar
<template> <YcComment author="张三" content="这是一条评论内容" datetime="2024-01-15 14:30:00" > <template #avatar> <YcAvatar style="background-color: #87d068"> <YcIcon-user /> </YcAvatar> </template> </YcComment> </template>
通过 author 插槽自定义作者内容。
author
<template> <YcComment avatar="https://via.placeholder.com/40x40" content="这是一条评论内容" datetime="2024-01-15 14:30:00" > <template #author> <span style="color: #1890ff; font-weight: bold;">张三</span> <YcTag color="blue" style="margin-left: 8px;">VIP用户</YcTag> </template> </YcComment> </template>
通过 datetime 插槽自定义时间显示。
datetime
<template> <YcComment author="张三" avatar="https://via.placeholder.com/40x40" content="这是一条评论内容" > <template #datetime> <YcTooltip content="2024-01-15 14:30:00"> <span>2小时前</span> </YcTooltip> </template> </YcComment> </template>
通过 content 插槽自定义评论内容。
content
<template> <YcComment author="张三" avatar="https://via.placeholder.com/40x40" datetime="2024-01-15 14:30:00" > <template #content> <div> <p>这是一条评论内容</p> <YcImage width="200" src="https://via.placeholder.com/200x150" alt="评论图片" /> </div> </template> </YcComment> </template>
通过 actions 插槽添加操作按钮。
actions
<template> <YcComment author="张三" avatar="https://via.placeholder.com/40x40" content="这是一条评论内容" datetime="2024-01-15 14:30:00" > <template #actions> <YcSpace> <YcButton type="text" size="small"> <YcIcon-like /> 点赞 </YcButton> <YcButton type="text" size="small"> <YcIcon-message /> 回复 </YcButton> <YcButton type="text" size="small"> <YcIcon-share /> 分享 </YcButton> </YcSpace> </template> </YcComment> </template>
通过 align 属性设置对齐方式。
align
<template> <YcSpace direction="vertical" size="large"> <YcComment author="张三" avatar="https://via.placeholder.com/40x40" content="左对齐的评论" datetime="2024-01-15 14:30:00" align="left" /> <YcComment author="李四" avatar="https://via.placeholder.com/40x40" content="右对齐的评论" datetime="2024-01-15 14:30:00" align="right" /> </YcSpace> </template>
通过对象形式设置不同元素的对齐方式。
<template> <YcComment author="张三" avatar="https://via.placeholder.com/40x40" content="这是一条评论内容" datetime="2024-01-15 14:30:00" :align="{ datetime: 'right', actions: 'left' }" > <template #actions> <YcSpace> <YcButton type="text" size="small">点赞</YcButton> <YcButton type="text" size="small">回复</YcButton> </YcSpace> </template> </YcComment> </template>
一个包含所有功能的完整评论示例。
<template> <YcComment author="张三" avatar="https://via.placeholder.com/40x40" content="这是一条评论内容,可以包含很长的文字描述。" datetime="2024-01-15 14:30:00" > <template #actions> <YcSpace> <YcButton type="text" size="small"> <YcIcon-like /> 点赞 (12) </YcButton> <YcButton type="text" size="small"> <YcIcon-message /> 回复 (3) </YcButton> <YcButton type="text" size="small"> <YcIcon-share /> 分享 </YcButton> </YcSpace> </template> <!-- 嵌套评论 --> <YcComment author="李四" avatar="https://via.placeholder.com/32x32" content="这是对张三评论的回复" datetime="2024-01-15 15:00:00" > <template #actions> <YcSpace> <YcButton type="text" size="small">点赞</YcButton> <YcButton type="text" size="small">回复</YcButton> </YcSpace> </template> </YcComment> </YcComment> </template>
string
''
CommentAlign
'left'
type CommentAlign = | 'left' | 'right' | { datetime?: 'left' | 'right'; actions?: 'left' | 'right' };
组件提供了多个样式类,可以通过 CSS 进行定制:
.yc-comment { /* 评论容器 */ } .yc-comment-avatar { /* 头像区域 */ } .yc-comment-inner { /* 评论内容区域 */ } .yc-comment-title { /* 标题区域(作者和时间) */ } .yc-comment-content { /* 评论内容 */ } .yc-comment-actions { /* 操作区域 */ } .yc-comment-inner-comment { /* 嵌套评论 */ }
Comment 评论
对网站内容的评论、讨论等。
何时使用
基础用法
最简单的用法,包含作者、头像、内容和时间。
嵌套评论
通过插槽实现嵌套评论。
自定义头像
通过
avatar
插槽自定义头像内容。自定义作者
通过
author
插槽自定义作者内容。自定义时间
通过
datetime
插槽自定义时间显示。自定义内容
通过
content
插槽自定义评论内容。操作区域
通过
actions
插槽添加操作按钮。对齐方式
通过
align
属性设置对齐方式。复杂对齐
通过对象形式设置不同元素的对齐方式。
完整示例
一个包含所有功能的完整评论示例。
API
Props
string
''
string
''
string
''
string
''
CommentAlign
'left'
Slots
Types
注意事项
样式定制
组件提供了多个样式类,可以通过 CSS 进行定制: