透過 100 多個技巧的集合來學習 Nuxt!

setPageLayout

setPageLayout 允許您動態變更頁面的版面配置。
setPageLayout 允許您動態變更頁面的版面配置。它依賴於存取 Nuxt context,因此只能在 Nuxt context 內呼叫。
middleware/custom-layout.ts
export default defineNuxtRouteMiddleware((to) => {
  // Set the layout on the route you are navigating _to_
  setPageLayout('other')
})
如果您選擇在伺服器端動態設定版面配置,*必須*在 Vue 渲染版面配置之前(亦即在插件或路由中介層內)執行此操作,以避免 hydration 不匹配。