【Nuxt】在 Nuxt3 中使用 Element Plus

安装 Element Plus 和图标库

shell 复制代码
pnpm add element-plus --save
pnpm add @element-plus/icons-vue

安装 Nuxt Element Plus 模块

shell 复制代码
pnpm add @element-plus/nuxt -D

配置 Nuxt 项目

nuxt.config.ts 中配置

shell 复制代码
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },
  typescript: {
    shim: false,
  },
  modules: ['@element-plus/nuxt'],
  css: ['element-plus/dist/index.css'],
})

在 .vue 文件中使用

类似写 vue3 项目,可以导入组件,也可以直接使用组件

html 复制代码
<script setup lang="ts">
import { Search } from '@element-plus/icons-vue'
</script>

<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <!-- <Header /> -->
        <el-icon>
          <Search />
        </el-icon>
        <el-button type="primary">Header</el-button>
      </el-header>
      <el-main>
        <router-view />
      </el-main>
      <el-footer>
        <!-- <Footer /> -->
        <el-button type="primary">Footer</el-button>
      </el-footer>
    </el-container>
  </div>
</template>

参考博客

在 Nuxt 3 中集成 Element Plus 的步骤
20分钟带你入门Nuxt3

相关推荐
mCell2 小时前
GSAP ScrollTrigger 详解
前端·javascript·动效
gnip2 小时前
Node.js 子进程:child_process
前端·javascript
excel6 小时前
为什么在 Three.js 中平面能产生“起伏效果”?
前端
excel7 小时前
Node.js 断言与测试框架示例对比
前端
天蓝色的鱼鱼8 小时前
前端开发者的组件设计之痛:为什么我的组件总是难以维护?
前端·react.js
codingandsleeping8 小时前
使用orval自动拉取swagger文档并生成ts接口
前端·javascript
石金龙9 小时前
[译] Composition in CSS
前端·css
白水清风9 小时前
微前端学习记录(qiankun、wujie、micro-app)
前端·javascript·前端工程化
Ticnix9 小时前
函数封装实现Echarts多表渲染/叠加渲染
前端·echarts
用户22152044278009 小时前
new、原型和原型链浅析
前端·javascript