Nuxt3-05layout

183 阅读1分钟

默认布局

// app.vue

<template>
  <NuxtLayout>
    <NuxtPage />
  </NuxtLayout>
</template>

根目录新建layouts目录

// default.vue

<template>
  <div class="layout">
    <header>default layout</header>
    <slot></slot>
  </div>
</template>

<script setup lang="ts"></script>

<style scoped>
.layout header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: pink;
  color: blue;
}
</style>

image.png

隐藏布局

// login.vue

<template>
  <div>login page</div>
</template>

<script setup lang="ts">
definePageMeta({
  layout: false,
});
</script>

<style scoped></style>

image.png

自定义布局

image.png

image.png

image.png

动态切换

在页面中通过使用setPageLayout()方法可以动态切换layout

setPageLayout('custom')