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 >.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54a39-5a317.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54a39-5a317.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?