useHeadSafe

推荐使用用户输入来提供头部数据。

useHeadSafe 可组合项是对 useHead 可组合项的封装器,它将输入限制为仅允许安全值。

¥The useHeadSafe composable is a wrapper around the useHead composable that restricts the input to only allow safe values.

用法

¥Usage

你可以传递与 useHead 相同的所有值

¥You can pass all the same values as useHead

useHeadSafe({
  script: [
    { id: 'xss-script', innerHTML: 'alert("xss")' }
  ],
  meta: [
    { 'http-equiv': 'refresh', content: '0;javascript:alert(1)' }
  ]
})
// Will safely generate
// <script id="xss-script"></script>
// <meta content="0;javascript:alert(1)">

:

Read more in https://unhead.unjs.io/docs/typescript/head/api/composables/use-head-safe.

阅读更多 Unhead 文档。

¥Read more on the Unhead documentation.

::

类型

¥Type

useHeadSafe(input: MaybeComputedRef<HeadSafe>): void

允许值列表如下:

¥The list of allowed values is:

const WhitelistAttributes = {
  htmlAttrs: ['class', 'style', 'lang', 'dir'],
  bodyAttrs: ['class', 'style'],
  meta: ['name', 'property', 'charset', 'content', 'media'],
  noscript: ['textContent'],
  style: ['media', 'textContent', 'nonce', 'title', 'blocking'],
  script: ['type', 'textContent', 'nonce', 'blocking'],
  link: ['color', 'crossorigin', 'fetchpriority', 'href', 'hreflang', 'imagesrcset', 'imagesizes', 'integrity', 'media', 'referrerpolicy', 'rel', 'sizes', 'type'],
}

有关更详细的类型,请参阅 @unhead/vue

¥See @unhead/vue for more detailed types.