Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt SEO meta tags through head property or computed property #623

Open
rickgoemans opened this issue Aug 15, 2022 · 1 comment
Open

Nuxt SEO meta tags through head property or computed property #623

rickgoemans opened this issue Aug 15, 2022 · 1 comment

Comments

@rickgoemans
Copy link

In the Nuxt framework you can set the page's meta SEO tags by using the local settings way which is done through the head property or a head getter function.

This works as intended but the drawback is that I can't use any functions or this reference to my knownledge, and this is crucial for having the page title translated using Vuei18n.

Normal non class-style components definition:

<script>
export default {
    //...
    head() {
        return {
            title: this.$t('LOGIN_PAGE_TITLE'),
        }
    },
</script>

I've tried to rework in 3 options that I can think off, but all give errors related to not being able to reach this.title or something related to $t not being available:

TypeError: Cannot read properties of undefined (reading '_t')
    at Vue.$t (vue-i18n.esm.js?a925:236:1)
    at Vue.get (index.vue?0f48:126:1)
    at Vue.get (index.vue?0f48:121:1)
    at eval (vue-class-component.esm.js?2fe1:193:1)
    at Array.forEach (<anonymous>)
    at componentFactory (vue-class-component.esm.js?2fe1:186:1)
    at eval (vue-class-component.esm.js?2fe1:311:1)
    at __decorate (tslib.es6.js?9ab4:58:1)
    at eval (index.vue?0f48:102:1)

Class style component

<script lang="ts">
import {Compont, Vue} from 'nuxt-propery-decorator'

@Component({
    // OPTION 1.
    // head: {
    //     title: $t('LOGIN_PAGE_TITLE'), // Error: _t(...) not available 
    // },
    
    // OPTION 2.
    // head: {
    //     title: this.title, // Error: this.title not available
    // },
})
export default class LoginPage extends Vue {
    // OPTION 3.
    // get head() {
    //     return {
    //         title: this.$t('LOGIN_PAGE_TITLE'), // Error: _t(...) not available
    //     }
    // }

    // OPTION 4.
    // get head() {
    //    return {
    //        title: this.title, // Error on the computed property that _t(...) is not available
    //    }
    // }

    get title(): string {
        return this.$t('LOGIN_PAGE_TITLE').toString()
    }
</script>

Am I overlooking some basic thing or is it just not possible to achieve with class style components?

@rickgoemans
Copy link
Author

Anybody with a suggestion? I'm still stuck at this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant