33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
//src\pages\test\markdown\index.tsx
|
|
import { useEffect, useState } from 'react';
|
|
import Markdown from '@/components/markdown2'; // 引入你刚刚创建的 Markdown 组件
|
|
|
|
export default function MarkdownPage() {
|
|
const [markdownContent, setMarkdownContent] = useState<string | null>(null);
|
|
|
|
// 使用 useEffect 钩子来加载 public 文件夹中的 Markdown 文件内容
|
|
useEffect(() => {
|
|
// 从 public 文件夹中获取文件内容
|
|
fetch('/md2.md')
|
|
|
|
.then((response) => response.text())
|
|
.then((text) => {
|
|
setMarkdownContent(text);
|
|
})
|
|
.catch((error) => {
|
|
console.error('Error loading Markdown file:', error);
|
|
});
|
|
}, []);
|
|
|
|
// 当文件内容加载后,显示 Markdown 组件
|
|
return (
|
|
<div style={{ padding: '20px' }}>
|
|
{markdownContent ? (
|
|
<Markdown>{markdownContent}</Markdown>
|
|
) : (
|
|
<p>Loading Markdown content...</p>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|