AsyncData of child page is unable to access parent's page's props

connecteev
0
connecteev
commented 5 months ago

Version

v2.10.2

Reproduction link

http://www.nourl.com

Steps to reproduce

Note that I am already aware of this:
https://nuxtjs.org/guide/async-data --> "You do NOT have access of the component instance through this inside asyncData because it is called before initiating the component."

However, I have a child page that I've passed a prop. I can't access the prop from asyncData of the child page.

  props: {
    searchQuery: {
      type: String,
      required: true
    },
  },
  computed: {
    getFeedUrl() {
      return '/' + process.env.backendPublicApiPrefix + '/search?q=' + this.searchQuery;
    },
  },

  async asyncData (context) {
    context.store.dispatch('resetPostFeed');
    let searchQuery = (context.route.query && context.route.query.q) ? context.route.query.q : '';
    await context.store.dispatch('retrievePosts', {'feedUrl': '/' + process.env.backendPublicApiPrefix + '/search?q=' + searchQuery, 'selection': 'alltime'} );
  },

As a more simplified example, I am trying to access 'searchQuery' prop in asyncData, but i'm not sure if I can get it from the context object.

The parent page does this:

              <nuxt-child 
              :key="$route.params.slug" 
              searchQuery="aaaaaaaaa"
              />

and in my child page (not component) I do this:

mounted() {
  console.log('mounted: searchQuery', this.searchQuery);
},
  async asyncData (context) {
console.log('asyncData: searchQuery', context.searchQuery);
}

The console.logs show this:

asyncData: searchQuery undefined
mounted: searchQuery aaaaaaaaa

Seems like this should be possible, but why is it not available from the context object?

What is expected ?

Seems like this should be possible, but why is it not available from the context object?

What is actually happening?

Props are inaccessible from AsyncData function of child pages

bug
0
connecteev
0
connecteev
commented 4 months ago

ping to keep this open

0
Informations
Bug Report โ€ข Open
#c9947 - Created 5 months ago