nuxt-community / nuxt-property-decorator

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

Class properties overrides asyncData, instead of vice versa #60

Closed patarapolw closed 4 years ago

patarapolw commented 4 years ago

This can easily be solved with removing class properties, but it makes it impossible to set default value for asyncData.

@Component({
  components: {
    PostQuery
  }
})
export default class Search extends Vue {
  // defaults = {
  //   posts: [],
  //   count: 0
  // };

  async asyncData({ $axios, $payloadURL, route }: any) {
    if(process.static && process.client && $payloadURL) {
      return await $axios.$get($payloadURL(route))
    }

    const ps = searchPosts({
      isBlog: true,
      current: true,
      posts: await axiosOrImport(`/build/posts.json`, hash.posts._header)
    });
    const posts = await Promise.all(ps.slice(0, config.posts.perPage).map(async (p) => {
      p.teaser = await teaserStore.get(p.path, p.h);
      return p;
    }));

   // this.defaults return defined

    return {
      defaults: {
        posts,
        count: ps.length
      }
    };
  }
}
patarapolw commented 4 years ago

It was a bug on my end, the upper code does work.