mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
feat: add <Html>
meta component (#1820)
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com> Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
parent
d9c1aa6b02
commit
abfbd2f34e
@ -23,28 +23,9 @@ export default {
|
||||
}
|
||||
```
|
||||
|
||||
## `head` Component Property
|
||||
|
||||
If you would prefer to use the options syntax, you can do exactly the same thing within your component options with an object or function called `head`. For example:
|
||||
|
||||
```js
|
||||
export default {
|
||||
head: {
|
||||
script: [
|
||||
{
|
||||
async: true,
|
||||
src: 'https://myscript.com/script.js'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Note that `head()` does not have access to the component instance.**
|
||||
|
||||
## Meta Components
|
||||
|
||||
Nuxt provides `<Title>`, `<Base>`, `<Script>`, `<Style>`, `<Meta>`, `<Link>`, `<Body>` and `<Head>` components so that you can interact directly with your metadata within your component template.
|
||||
Nuxt provides `<Title>`, `<Base>`, `<Script>`, `<Style>`, `<Meta>`, `<Link>`, `<Body>`, `<Html>` and `<Head>` components so that you can interact directly with your metadata within your component template.
|
||||
|
||||
Because these component names match native HTML elements, it is very important that they are capitalized in the template.
|
||||
|
||||
@ -56,11 +37,13 @@ For example:
|
||||
<template>
|
||||
<div>
|
||||
Hello World
|
||||
<Head :lang="dynamic > 50 ? 'en-GB' : 'en-US'">
|
||||
<Title>{{ dynamic }} title</Title>
|
||||
<Meta name="description" :content="`My page's ${dynamic} description`" />
|
||||
<Link rel="preload" href="/test.txt" as="script" />
|
||||
</Head>
|
||||
<Html :lang="dynamic > 50 ? 'en-GB' : 'en-US'">
|
||||
<Head>
|
||||
<Title>{{ dynamic }} title</Title>
|
||||
<Meta name="description" :content="`My page's ${dynamic} description`" />
|
||||
<Link rel="preload" href="/test.txt" as="script" />
|
||||
</Head>
|
||||
</Html>
|
||||
|
||||
<button class="blue" @click="dynamic = Math.random() * 100">
|
||||
Click me
|
||||
|
@ -2,11 +2,13 @@
|
||||
<div>
|
||||
Hello World
|
||||
|
||||
<Head :lang="'' + dynamic">
|
||||
<Title>{{ dynamic }} title</Title>
|
||||
<Meta name="description" :content="`My page's ${dynamic} description`" />
|
||||
<Link rel="preload" href="/test.txt" as="script" />
|
||||
</Head>
|
||||
<Html :lang="String(dynamic)">
|
||||
<Head>
|
||||
<Title>{{ dynamic }} title</Title>
|
||||
<Meta name="description" :content="`My page's ${dynamic} description`" />
|
||||
<Link rel="preload" href="/test.txt" as="script" />
|
||||
</Head>
|
||||
</Html>
|
||||
|
||||
<button class="blue" @click="dynamic = Math.random() * 100">
|
||||
Clickme
|
||||
|
@ -193,13 +193,19 @@ export const Style = defineComponent({
|
||||
// <head>
|
||||
export const Head = defineComponent({
|
||||
name: 'Head',
|
||||
setup: (_props, ctx) => ctx.slots.default
|
||||
})
|
||||
|
||||
// <html>
|
||||
export const Html = defineComponent({
|
||||
name: 'Html',
|
||||
props: {
|
||||
...globalProps,
|
||||
manifest: String,
|
||||
version: String,
|
||||
xmlns: String
|
||||
},
|
||||
setup: setupForUseMeta(headAttrs => ({ headAttrs }), true)
|
||||
setup: setupForUseMeta(htmlAttrs => ({ htmlAttrs }), true)
|
||||
})
|
||||
|
||||
// <body>
|
||||
|
Loading…
Reference in New Issue
Block a user