创建社交媒体 Footer
准备好…
- 创建一个页脚组件
- 创建并传递参数到一个社交媒体组件
现在你已经在页面上使用了 Astro 组件,是时候在一个组件中使用另一个组件!
创建一个页脚组件
段落标题 创建一个页脚组件-
创建一个新文件:
src/components/Footer.astro
。 -
将以下代码复制到你的新文件
Footer.astro
中。src/components/Footer.astro ---const platform = "github";const username = "withastro";---<footer><p>在 <a href={`https://www.${platform}.com/${username}`}>{platform}</a> 上,了解有关我的项目的更多信息!</p></footer>
导入并使用 Footer.astro
段落标题 导入并使用 Footer.astro-
在每个 Astro 页面(
index.astro
、about.astro
和blog.astro
)的前置元数据中添加以下导入语句:import Footer from '../components/Footer.astro'; -
在每个页面的 Astro 模板中,在
</body>
标签之前添加一个新的<Footer />
组件,以在页面底部显示页脚。<Footer /></body></html>