Skip to content

Commit 9f0f03d

Browse files
authored
Merge branch 'main' into 092803
2 parents 282035d + 65a0b37 commit 9f0f03d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/content/docs/zh-cn/guides/images.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,33 @@ import Logo from '../assets/logo.svg';
432432
<Logo width={64} height={64} fill="currentColor" />
433433
```
434434

435+
#### `SvgComponent` 类型
436+
437+
<Since v="5.14.0" />
438+
439+
你也可以使用 `SvgComponent` 类型对 `.svg` 资源强制实施类型安全:
440+
441+
```astro title="src/components/Logo.astro"
442+
---
443+
import type { SvgComponent } from "astro/types";
444+
import HomeIcon from './Home.svg'
445+
446+
interface Link {
447+
url: string
448+
text: string
449+
icon: SvgComponent
450+
}
451+
452+
const links: Link[] = [
453+
{
454+
url: '/',
455+
text: 'Home',
456+
icon: HomeIcon
457+
}
458+
]
459+
---
460+
```
461+
435462
### 创建自定义图像组件
436463

437464
你可以通过将 `<Image />``<Picture/>` 组件包装在另一个 Astro 组件中来创建自定义、可重用的图像组件。这允许你只设置一次默认属性和样式。

0 commit comments

Comments
 (0)