npx nuxi init nuxt-app || pnpm dlx nuxi init nuxt-app
yarn install || npm install || pnpm install --shamefully-hoist
yarn dev -o || npm run dev -- -o || pnpm run dev -o
✨ 项目启动!http://localhost:3000 自动打开一个浏览器窗口。
根目录│ .nuxt // dev运行之后自动生成│ .output // 打包编译之后生成的文件│ assets // 静态文件│ components // 组件文件夹│ composables // 会自动导入依赖项,不需要手动引入│ content // 必须下载@nuxt/content 才能使用该文件夹│ layouts // 公共布局目录│ middleware // 中间件│ node_modules // 依赖│ pages // 页面文件夹│ public // 不会被打包的静态文件夹│ server // 服务端目录│ app.vue // 入口文件│ nuxt.config.ts // 配置文件│ package.json // 包含应用程序的所有依赖项和脚本└─ tsconfig.json // 自动生成的文件
yarn add element-plus || npm install element-plus// 如果使用icon 需要下载 @element-plus/icons-vueyarn add @element-plus/icons-vue || npm install @element-plus/icons-vue
// 判断运行环境const lifecycle = process.env.npm_lifecycle_eventimport { defineNuxtConfig } from 'nuxt'export default defineNuxtConfig({ // ... 其他配置 build: { transpile: lifecycle === 'build' ? ['element-plus'] : [], },})
// 下载按需引入的依赖包yarn add unplugin-auto-import unplugin-vue-components// 判断运行环境export default defineNuxtConfig({ // ... 其他配置 vite: { plugins: [ AutoImport({ resolvers: [ElementPlusResolver()] }), Components({ dts: true, resolvers: [ElementPlusResolver()] }), visualizer, ] }})
import { ElSwitch, ElDrawer } from 'element-plus/dist/index.full.js' import { Check, Close } from '@element-plus/icons-vue' · <el-switch v-model="false" class="ml-2" inline-prompt :active-icon="Check" :inactive-icon="Close" />
@nuxt/content Markdown 渲染 使用 el-drawer 踩的坑
Hydration children mismatch in <div>: server rendered element contains more child nodes than client vdom.
// 需要把 append-to-body 设置为true// Drawer 自身是否插入至 body 元素上。嵌套的 Drawer 必须指定该属性并赋值为 true· <el-drawer :append-to-body="true"></el-drawer>