nuxt-community / nuxt-property-decorator

Property decorators for Nuxt (base on vue-property-decorator)
https://github.com/kaorun343/vue-property-decorator
MIT License
400 stars 34 forks source link

`watchQuery` can't work with `v2.1.3` #34

Closed shalldie closed 5 years ago

shalldie commented 5 years ago

watchQuery can't work with v2.1.3

I tried it like this:

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

@Component({
     ...
})
export default class IndexPage extends Vue {

    watchQuery: string[] = ['label', 'page'];
...

So strange, i see other hooks like asyncData works well, but watchQuery does nothing when query changes.

Here is a repository to show a demo: https://github.com/shalldie/nuxt-ts-watchQuery

husayt commented 5 years ago

Thanks for reporting. Let me investigate to see what's going on there.

hartmut-co-uk commented 5 years ago

Hi @shalldie it's part of ComponentOptions... try following:

@Component({
  ...,
  watchQuery: ['label', 'page']
})
export default class IndexPage extends Vue {    
...
shalldie commented 5 years ago

@hartmut-co-uk

yes it works for me. Thank u.

But it seems that i should to write the .d.ts extend for type ComponentOptions by myself?

This lib says it add hooks for class, so i think watchQuery could be a field/method of class ,which likes asyncData.

hartmut-co-uk commented 5 years ago

Apologies, I didn't notice there's been new releases since yesterday - I'll have another look tomorrow.

shalldie commented 5 years ago

I found that,

watchQuery must be part of ComponentOptions layout must be a static field of class.

I think thease should be the fields of class instance, or, a description should be in the readme.md

husayt commented 5 years ago

@shalldie have this been resolved or you still have the problem?

shalldie commented 5 years ago

@husayt it works with what @hartmut-co-uk said, let me close this issue.

genu commented 4 years ago

Can we have some clarity here? I don't think I understand the accepted workaround.

I get typing error when I add watchQuery to @Component

image