Vue-meta: How can we use it with vue-class-component?

Created on 25 Apr 2017  路  5Comments  路  Source: nuxt/vue-meta

I am trying examples with https://github.com/vuejs/vue-class-component but it doesn't work like below:

export default class App extends Vue {
    metaInfo = {
      title: 'Title'
    }
}

Most helpful comment

@vishr, I use it like that and it works fine:

@Component
export default class Home extends Vue {

   public metaInfo(): any {
        return {
            meta: [
                { name: 'description', content: 'Test description' },
                { name: 'keywords', content: 'Test keywords' },
            ],
            title: 'Test Title',
        };
    }
}

Also, as @Atinux said, I've to add custom metaInfo hook.

All 5 comments

It works like below:

@Component({
  metaInfo: {
    title: title
})

@vishr please look at https://github.com/vuejs/vue-class-component#adding-custom-hooks

import Component from 'vue-class-component'

Component.registerHooks([
  'metaInfo'
])

@Atinux Thanks for your response, I will have a look it.

@vishr, I use it like that and it works fine:

@Component
export default class Home extends Vue {

   public metaInfo(): any {
        return {
            meta: [
                { name: 'description', content: 'Test description' },
                { name: 'keywords', content: 'Test keywords' },
            ],
            title: 'Test Title',
        };
    }
}

Also, as @Atinux said, I've to add custom metaInfo hook.

Just to mention it in case someone else runs into it, the vue-class-component docs on additional hooks are now at https://class-component.vuejs.org/guide/additional-hooks.html, and it's essential that you register the metaInfo hook before defining any components (as described in the docs). Otherwise, metadata won't be updated when a component is initially mounted (although it will update after hot-reload), and you'll get This vue app/component has no vue-meta configuration if you manually call this.$meta().refresh().

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hurradieweltgehtunter picture hurradieweltgehtunter  路  4Comments

iMomen picture iMomen  路  5Comments

diff-dennis picture diff-dennis  路  8Comments

dysol picture dysol  路  6Comments

terazus picture terazus  路  8Comments