This commit is contained in:
32
src/pages/test/markdown/22.tsx
Normal file
32
src/pages/test/markdown/22.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
//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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user