How does nuxt.js get the context object in a custom layout page?

as the title

header footer layout

layout

```
<div>
    <SideBar></SideBar>
    <Header></Header>
    <nuxt/>
    <Footer></Footer>
</div>
```

but the logic of the hearder and footer components needs to get the context object on the server, but the asyncData function cannot be used in the layout page to get the context.

ask the gods how to get the context object in the layout page

Dec.18,2021

Hi, have you found the answer? I also encountered this problem


I was stopped by the same problem. Have the two brothers upstairs found a solution?


this problem was encountered yesterday and has just been solved. AsyncData can only be used under the page directory.

if you want to use context in layout, you can use middleware https://zh.nuxtjs.org/api/pag.

.
< H1 > can be used in the data function or in created to obtain the context,nuxt of vue ssr through this.$ssrContext . The ssr cannot be obtained < / H1 >.
Menu