export default { data: function () { return { title: 'My Title' } }, // Usage with context the component head: { // To use "this" in the component, it is necessary to return the object through a function title: function () { return { inner: this.title } }, meta: [ { name: 'description', content: 'My description', id: 'desc' } ] } ... }}
You can customize the page title with tab and complement, just add the properties separator and complement object in title
Separator by default uses the pipe character | and complement by default uses the title of the html document
If you'd like to set default custom title options on every component you can pass options to VueHead when you're registering it for Vue, just like in example below.
There are some tags that are unique and that only need to update the content, such as meta tags name="description" or rel="canonical".
Therefore, it is necessary to define a id, so that the element is found and is made the update correctly, avoiding duplicates tags.
meta: [ { name: 'description', content: 'A description of the page', id: 'desc' }]
Event emitted
Vue 1.*
At some point you may want to do something after the DOM is complete with the changes, to this the vue-head emits through the key okHead.
With this, you can hear through the events option of your instance component.
// omitedevents: { okHead: function () { // Do something }},
Vue 2.*
created: function () { this.$on('okHead', function () { // Do Something });}
Update elements with asynchronous data or after page loaded
Keep the data tags updated through an update of the elements that have changed data, which are the reactive data of your component.
It is not automatic if you want to upgrade, simply issue the event updateHead soon after changing your data.
For example:
// omitedmethods: { getAsyncData: function () { var self = this window.setTimeout(function () { self.title = 'My async title' self.$emit('updateHead') }, 3000) }},
Note: I recommend you use the vueRouter to request the data from the tags and build the header tags with synchronous data, updating real-time meta tags only have to use the business rules of your application.
Keep alive
Supported only in Vue next >2.0.*, Because it uses the new hooks activated and deactivated. Obs: In version <1.0. * Using making prompt to maintain the element in the document.
Shorthand property
property
shorthand
used tags
charset
ch
meta
target
tg
base
name
n
meta
http-equiv
he
meta
itemprop
ip
meta
content
c
meta
property
p
meta
rel
r
link
href
h
link
sizes
sz
link
type
t
linkstylescript
scheme
sc
script
src
s
script
async
a
script
defer
d
script
inner
i
scriptstyle
Support
Vue.js 2.0.*
Vue.js 1.0.*
Contributing
Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found.
Fork repository, make changes, add your name and link in the authors session readme.md
Send a pull request
If you want a faster communication, find me on @ktquez