Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@vueuse/head
Advanced tools
Document head manager for Vue 3.
💛 Support the ongoing development of this project by becoming a GitHub Sponsor.
npm i @vueuse/head
# Or Yarn
yarn add @vueuse/head
Register the Vue plugin:
import { createApp } from 'vue'
import { createHead } from '@vueuse/head'
const app = createApp()
const head = createHead()
app.use(head)
app.mount('#app')
Manage head
with the composition API useHead
in your component:
<script>
import { defineComponent } from 'vue'
import { useHead } from '@vueuse/head'
export default defineComponent({
setup() {
useHead(() => ({
title: `Website title`,
meta: [
{
name: `description`,
content: `Website description`,
},
],
}))
},
})
</script>
import { renderToString } from '@vue/server-renderer'
import { renderHeadToString } from '@vueuse/head'
const appHTML = await renderToString(yourVueApp)
// `head` is created from `createHead()`
const { headTags, htmlAttrs, bodyAttrs } = renderHeadToString(head)
const finalHTML = `
<html${htmlAttrs}>
<head>
${headTags}
</head>
<body${bodyAttrs}>
<div id="app">${appHTML}</div>
</body>
</html>
`
createHead()
Create the head manager instance.
useHead(() => HeadObj)
interface HeadObj {
title?: string
base?: Attrs
meta?: Attrs[]
link?: Attrs[]
style?: Attrs[]
script?: Attrs[]
htmlAttrs?: Attrs
bodyAttrs?: Attrs
}
interface Attrs {
[attrName: string]: any
}
For meta
tags, we use name
and property
to prevent duplicated tags, you can instead use the key
attribute if the same name
or property
is allowed:
useHead({
meta: [
{
property: 'og:locale:alternate',
content: 'zh',
key: 'zh',
},
{
property: 'og:locale:alternate',
content: 'en',
key: 'en',
},
],
})
To set the textContent
of an element, use the children
attribute:
useHead({
style: [
{
children: `body {color: red}`,
},
],
})
renderHeadToString(head: Head)
HtmlResult
interface HtmlResult {
// Tags in `<head>`
readonly headTags: string
// Attributes for `<html>`
readonly htmlAttrs: string
// Attributes for `<body>`
readonly bodyAttrs: string
}
Render the head manager instance to HTML tags in string form.
MIT © EGOIST
FAQs
Document head manager for Vue 3. SSR ready.
The npm package @vueuse/head receives a total of 100,083 weekly downloads. As such, @vueuse/head popularity was classified as popular.
We found that @vueuse/head demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.