index.ts
基本信息
- 类型: TypeScript Barrel 文件
- 路径:
./src/components/comments/index.ts
功能描述
评论组件模块的导出文件(Barrel Pattern),集中导出评论相关的所有组件,简化其他文件中的导入语句。
导出内容
| 导出名称 | 来源路径 | 描述 |
|---|---|---|
CommentForm | ./comment-form | 评论表单组件 |
CommentItem | ./comment-item | 评论项组件 |
CommentSection | ./comment-section | 评论区块组件 |
使用方式
// 通过 Barrel 文件导入(推荐)
import { CommentForm, CommentItem, CommentSection } from "@/components/comments";
// 直接导入(不推荐)
import { CommentForm } from "@/components/comments/comment-form";
import { CommentItem } from "@/components/comments/comment-item";
import { CommentSection } from "@/components/comments/comment-section";
优势
- 简化导入路径
- 统一组件入口
- 便于重构时调整内部文件结构
- 提高代码可维护性