vue-simple-headful
This is a direct and fully reworked fork of vue-headful. It is meant to make headful interactions simpler and more diverse for Vue.js. It can be used as a replacement for original vue-headful if more simplicity or richer functionality needed.
vue-simple-headful is a tiny wrapper around Headful, a generic library to set meta tags with JavaScript.
npm i -S vue-simple-headful yarn add vue-simple-headful
Usage
Register the plugin
And then use the headful
component option in any of your views.
Plugin options
Optinally you can define custom opions for a plugin:
1. A custom key to use with your components' options:
and then in some component.vue
:
2. A boolean flag if you want to use a special vue-component (false by default):
then in any template:
Headful shorthand
The plugin also adds a shorthand for headful in every vue instance as $headful
(or as $[your custom key]
).
Plugin Usage
As function
As arrow function
As component data
As an object
Component Usage
vue-headful component supports all the head properties that are supported by Headful.
You can find a non-complete list of head properties in the following example:
If there are any other head properties or attributes you want to set, you can use html
(for arbitrary elements in the whole document) or head
(for elements within <head>
) as follows.
The selectors can be any valid CSS selector.
If you want to remove a previously defined attribute from an element, you can set it to undefined
as in the example below:
Description
vue-simple-headful is only a wrapper around Headful and by itself does not do that much.
vue-simple-headful supports all the head properties that are supported by Headful.
You can find a non-complete list of head properties in the following example:
JS:
HTML
If there are any other head properties or attributes you want to set, you can use html
(for arbitrary elements in the whole document) or head
(for elements within <head>
) as follows.
The selectors can be any valid CSS selector.
JS:
HTML:
If you want to remove a previously defined property, you can set it to undefined
as in the example below:
JS:
HTML:
IMPORTANT
Note that neither Headful nor vue-headful add missing HTML elements, they only add attribute values.
So it is important that you add everything that you want to have populated in your HTML first.
For example, to specify the title and description you have to prepare the HTML as follows.
vue-headful also supports dynamic properties and adds watchers to everything.
That means you can also set head properties asynchronously, for example after an API request.
Also see the non-complete list of meta tags and other head properties you can define using vue-headful:
<html lang>
<title>
<meta name="description">
<meta itemprop="description">
<meta property="og:description">
<meta name="twitter:description">
<meta name="keywords">
<meta itemprop="image">
<meta property="og:image">
<meta name="twitter:image">
<meta property="og:locale">
<link rel="canonical">
<meta property="og:url">
<meta name="twitter:url">