# @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)

Latest version **0.1.8** (published 2020-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @egoist/vue-head
pnpm add @egoist/vue-head
yarn add @egoist/vue-head
bun add @egoist/vue-head
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.8 |
| Published | 2020-07-26 |
| First published | 2020-07-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 95 |
| Author | EGOIST |
| Maintainers | egoist |

## Links

- npm: https://www.npmjs.com/package/@egoist/vue-head
- Repository: https://github.com/egoist/vue-head
- npm.io page: https://npm.io/package/@egoist/vue-head

## Recent versions

- 0.1.8 (latest) — 2020-07-26
- 0.1.7 — 2020-07-26
- 0.1.6 — 2020-07-24
- 0.1.5 — 2020-07-24
- 0.1.4 — 2020-07-24
- 0.1.3 — 2020-07-24
- 0.1.2 — 2020-07-24
- 0.1.1 — 2020-07-24

## README

# @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 `<head>` 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 `<Head>` component to add tags to `<head>`:

```vue
<template>
  <Head>
    <title>Hello Vue</title>
    <meta name="description" content="Do you like it?" />
  </Head>
</template>

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

export default {
  components: {
    Head,
  },
}
</script>
```

## 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.headTags))

const finalHTML = `
<html>

<head>${headHTML}</head>

<body>${appHTML}</body>

</html
`
```

## How does it work

On the client-side, head tags are `<Teleport>`-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 &copy; [EGOIST](https://github.com/egoist/vue-head)

---
_Source: https://npm.io/package/@egoist/vue-head · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
