代码拉取完成,页面将自动刷新
一个支持markdowm和emoji评论组件,无需任何配置,无需申请任何账号,即引即用
import {initComment} from 'tc-comment';
initComment({
appName: 'xxx', // 自己起一个你的应用名称
});
cdn 使用
<script src="https://cdn.jsdelivr.net/npm/tc-comment/tc-comment.min.js"></script>
<script>
TComment.initComment({
appName: 'xxx', // 自己起一个你的应用名称
});
</script>
// ...
import {Comment} from 'tc-comment';
Comment.init({appName: 'xxx'}); // 自己起一个你的应用名称
export default {
components: {Comment},
// ...
}
initComment({
appName: string;
el?: HTMLElement | string; // Comment.init 传入该参数无效
theme?: 'dark' | 'light';
darkSelector?: string;
services?: {
insertComment: InsertComment;
getComment: GetComment;
insertReply: InsertReply;
};
urlConfig?: {
host: string;
get?: string;
insert?: string;
reply?: string;
};
dataHandler?: {
get?: (data: IGetOption) => any;
insert?: (data: IComment) => any;
reply?: (data: IReply) => any;
};
})
// Comment.init 参数与上述参数一致
tc-comment 支持自定义方法来实现你自己的请求方法
import {initComment} from 'tc-comment';
initComment({
el: '#app',
services: { // 请自行注入三个请求 插入评论 插入回复 和 获取评论
insertComment(){
},
getComment(){
},
getComment(){
}
}
});
insertComment 和 getComment ts声明
interface InsertComment {
(data: {
name: string;
contact: string;
content: string;
}): Promise<boolean>;
}
interface InsertReply {
(data: {
name: string;
contact: string;
content: string;
commentId: number;
}): Promise<boolean>;
}
interface GetComment {
(query: {
index?: number;
size?: number;
all?: boolean;
condition?: object;
}): Promise<Array<{
createTime: number;
name: string;
content: string;
}>>;
}
tc-comment 支持通过配置 urlConfig 自定义接口
urlConfig 参数优先级低于 services参数
import {initComment} from 'tc-comment';
initComment({
el: '#app',
urlConfig: {
host:'www.example.com',
get:'/api/comment/get',
insert:'/api/comment/insert',
reply:'/api/reply/insert'
},
});
使用 urlConfig 参数的话,tc-comment 会调用该域名下面的三个接口,请自行部署
CommentObject
{
id: number;
name: string;
contact: string;
content: string;
createTime: number; // 时间戳
reply: Array<{
name: string;
contact: string;
content: string;
createTime: number; // 时间戳
}>;
}
使用自定义 urlConfig时 可以搭配 dataHandle 修改请求数据
使用方式如下
import {initComment} from 'tc-comment';
initComment({
el: '#app',
urlConfig: {
host:'www.example.com',
get:'/api/comment/get',
insert:'/api/comment/insert',
reply:'/api/reply/insert'
},
dataHandler: {
get: (data) => {return data},
insert: (data) => {return data},
reply: (data) => {return data},
}
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。