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

Cannot access this inside head #87

Open
komninoschatzipapas opened this issue Feb 17, 2021 · 2 comments
Open

Cannot access this inside head #87

komninoschatzipapas opened this issue Feb 17, 2021 · 2 comments

Comments

@komninoschatzipapas
Copy link

komninoschatzipapas commented Feb 17, 2021

I have a component that calculates the page title on asyncData. It looks like this:

import { Component, Vue } from 'nuxt-property-decorator';

@Comonent({
  head() { return { title: this.title } },
  asyncData(ctx) {
    // Calculate title dynamically
    return { title: 'abc' }
  } 
})
export default Comp extends Vue {
  title!: string;
}

But I get an error while trying to access this inside head:

Property 'title' does not exist on type 'Vue'. Vetur(2339)

Is it possible to achieve this functionality? If yes, how exactly?

@amjmhs
Copy link

amjmhs commented Mar 10, 2021

Why not use the head-hook ?

@maxdzin
Copy link

maxdzin commented Dec 1, 2021

@komninoschat You can use it by specifying this as a parameter for the head.
Using your example it will look this way:

import { Component, Vue } from 'nuxt-property-decorator';

@Comonent({
  head(this: Comp) { return { title: this.title } },
  asyncData(ctx) {
    // Calculate title dynamically
    return { title: 'abc' }
  } 
})
export default Comp extends Vue {
  title!: string;
}

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

3 participants