[英]Put some elements from component into head tag
我想要從 component 到 go 到head
標簽的一些標簽。 我想放入名為head
的slot
中。 怎么能做到這一點?
布局.astro
<html>
<head>
<slot name="head" />
</head>
<body>
<slot />
<mycomponent />
</body>
</html>
我的組件.astro
<link .... slot="head">
<div>
...
</div>
可以放置一個標簽,但只能從你調用放置單個<head>
的布局的地方使用像這樣的slots
在 Layout.astro 中創建一個
name="head"
但你可以使用任何名稱
<head>
<title>{title}</title>
<slot name="head"/>
</head>
<body>
<slot />
</body>
然后在您的頁面或調用布局的組件中
<Layout title="Welcome to Astro.">
<link slot="head" rel="icon" type="image/svg+xml" href="/favicon.svg" />
<main>
<h1>Astro</h1>
</main>
</Layout>
<head>
元素,所有其他使用的<head>
標簽將保留在原處,不會被編譯器移動到主頂部<head>
<head>
標簽內填充 it 標簽注意:下面來自 Astro 文檔網站的參考建議“將單個<head>
及其內容放在布局組件中。”
https://docs.astro.build/en/guides/troubleshooting/#using-head-in-a-component
命名插槽: https://docs.astro.build/en/core-concepts/astro-components/#named-slots
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.