Skip to content

布局系统

默认布局

src/layouts/default.vue 将作为默认布局。

html
<!-- src/layouts/default.vue -->
<template>
	我是默认布局
	<router-view />
	<!-- 页面视图出口 -->
</template>

此时 src/pages/index.vue

html
<!-- src/pages/index.vue -->
<template>
	<div>我是首页</div>
</template>

路由到 /时,页面将渲染

html
我是默认布局 我是首页

此时 src/pages/about.vue

html
<!-- src/pages/about.vue -->
<template>
	<div>我是关于页</div>
</template>

路由到 /about 时,页面将渲染

html
我是默认布局 我是关于页

非默认布局

随便创建一个 src/layouts/custom.vue

html
<!-- src/layouts/custom.vue -->
<template>
	我是非默认布局custom
	<router-view />
	<!-- 页面视图出口 -->
</template>

此时 src/pages/index.vue

html
<!-- src/pages/index.vue -->
<template>
	<div>我是首页</div>
</template>

<!-- 添加自定义块 👇 -->
<route lang="json">
{
	"meta": {
		"layout": "custom"
	}
}
</route>

此时路由到 /, 页面将渲染

html
我是非默认布局custom 我是首页

具体可见 👉 vite-plugin-vue-meta-layouts