setPageLayout 允许你动态更改页面的布局。它依赖于访问 Nuxt 上下文,因此只能在Nuxt 上下文内调用。export default defineNuxtRouteMiddleware((to) => {
// 在你要导航到的路由上设置布局
setPageLayout('other')
})
You can pass props to the layout by providing an object as the second argument:
export default defineNuxtRouteMiddleware((to) => {
setPageLayout('admin', {
sidebar: true,
title: 'Dashboard',
})
})
The layout can then receive these props:
<script setup lang="ts">
const props = defineProps<{
sidebar?: boolean
title?: string
}>()
</script>
<template>
<div>
<aside v-if="sidebar">
Sidebar
</aside>
<main>
<h1>{{ title }}</h1>
<slot />
</main>
</div>
</template>