Nuxt.js: Pass props to nuxt-child

Created on 17 Apr 2018  路  6Comments  路  Source: nuxt/nuxt.js

What problem does this feature solve?

Hi,
I have nested routes.
In the container I'm doing some actions to fetch api, write in store, create computed objects, etc..
I need them in the container, but I also need them in the children pages.
It would be really cool to be able to pass props to children pages to avoid to re-do all this operations on all the nested pages.

Thanks!

What does the proposed changes look like?

// container
<div>
   <UserInfos :user="user">
   <Tabs>
   <nuxt-child :user="user"/>
</div>
// nested
props: {
   user : {}
},

This feature request is available on Nuxt.js community (#c6920)
feature-request

Most helpful comment

This feature-request has been implemented by @Atinux, @clarkdo.

This works in latest nuxt-edge

pages/child.vue:

<template>
  <nuxt-child :test="'RESOLVE_PLZ'"/>
</template>

pages/child/index.vue:

<template><h1> DO IT! </h1> </template>
<script>
export default {
  props: ["test"],
  mounted(){
    console.log(this.test) //RESOLVE_PLZ
  }
}
</script>

All 6 comments

If we could have nested layouts, it could solve your issue I suppose?

@lucpotage hem... Sorry I don't see the link with nested layout. 馃槙

@mathieutu OK, I thought that layout data was automatically passed to the pages depending on it but it's not the case.

It seems the store is the only solution to your problem: https://github.com/nuxt/nuxt.js/issues/1894

This feature-request has been implemented by @Atinux, @clarkdo.

This works in latest nuxt-edge

pages/child.vue:

<template>
  <nuxt-child :test="'RESOLVE_PLZ'"/>
</template>

pages/child/index.vue:

<template><h1> DO IT! </h1> </template>
<script>
export default {
  props: ["test"],
  mounted(){
    console.log(this.test) //RESOLVE_PLZ
  }
}
</script>

Thank you guys!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uptownhr picture uptownhr  路  3Comments

danieloprado picture danieloprado  路  3Comments

maicong picture maicong  路  3Comments

bimohxh picture bimohxh  路  3Comments

vadimsg picture vadimsg  路  3Comments