--- name: vite-plugin-uni-layouts description: Nuxt-like layouts system for Vite-powered uni-app projects --- # vite-plugin-uni-layouts Provides a Nuxt-like layout system for uni-app. Wraps pages with reusable layout components. ## Installation ```bash npm i -D @uni-helper/vite-plugin-uni-layouts ``` ## Setup ```ts // vite.config.ts import uni from '@dcloudio/vite-plugin-uni' import UniLayouts from '@uni-helper/vite-plugin-uni-layouts' import { defineConfig } from 'vite' export default defineConfig({ plugins: [UniLayouts(), uni()], }) ``` ## Creating Layouts Create layout files in `src/layouts/` directory: ```vue ``` ## Applying Layouts ### Via pages.json (traditional) ```json { "pages": [{ "path": "pages/index/index", "layout": "default" }, { "path": "pages/about/index", "layout": false // Disable layout }] } ``` ### Via definePage (recommended) ```vue ``` ## Dynamic Layouts Use the `` component for dynamic layout switching: ```vue ``` ### Accessing Layout Ref ```vue ``` Options API: ```vue ``` ## How It Works The plugin does two things: 1. Auto-scans and globally registers components from `layouts/` directory 2. Wraps pages with the specified layout component > **Note:** WeChat Mini Program limitation - If using `web-view` component, layout wrapping may not work properly. ## Configuration See [type definitions](https://github.com/uni-helper/vite-plugin-uni-layouts/blob/main/src/types.ts) for all options.