Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/egoist/vue-head

Document <head> manager for Vue 3, SSR ready.
https://github.com/egoist/vue-head

Last synced: about 2 months ago
JSON representation

Document <head> manager for Vue 3, SSR ready.

Awesome Lists containing this project

README

        

# Use [@vueuse/head](https://github.com/vueuse/head) instead.

# @egoist/vue-head

[![npm version](https://badgen.net/npm/v/@egoist/vue-head)](https://npm.im/@egoist/vue-head) [![size](https://badgen.net/bundlephobia/minzip/@egoist/vue-head)](https://bundlephobia.com/result?p=@egoist/vue-head)

Document `` manager for Vue 3, SSR ready. (Experimental)

## Install

```bash
yarn add @egoist/vue-head
```

## Usage

Apply this plugin to your Vue instance:

```js
import { createApp } from 'vue'
import { createHead } from '@egoist/vue-head'

const app = createApp()
const head = createHead()

app.use(head)
```

Use the `` component to add tags to ``:

```vue


Hello Vue

import { Head } from '@egoist/vue-head'

export default {
components: {
Head,
},
}

```

## SSR Usage

On your server:

```js
import { createApp, h, Fragment } from 'vue'
import { renderToString } from '@vue/server-renderer'

const app = createApp()
const appHTML = await renderToString(app)
const headHTML = await renderToString(
h(Fragment, app.config.globalProperties.$head.headTags)
)

const finalHTML = `

${headHTML}

${appHTML}

`-ed to `document.head` element.

On the server-side, head tags are stored as a VNode array, so you can render them to HTML using `Vue.renderToString`.

## TODO

- Testing
- Support `bodyAttrs`, `htmlAttrs`

## Prior Art

Inspired by `react-head`.

## License

MIT © [EGOIST](https://github.com/egoist/vue-head)