【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

相关推荐
kyriewen31 分钟前
产品经理把PRD写成“天书”,我用AI半小时重写了一遍,他当场愣住
前端·ai编程·cursor
humcomm1 小时前
元框架的工作原理详解
前端·前端框架
canonical_entropy1 小时前
Attractor Before Harness: AI 大规模开发的方法论
前端·aigc·ai编程
zhangxingchao2 小时前
多 Agent 架构到底怎么选?从 Claude Agent Teams、Cognition/Devin 到工程落地原则
前端·人工智能·后端
IT_陈寒2 小时前
SpringBoot那个自动配置的坑,害我排查到凌晨三点
前端·人工智能·后端
Honor丶Onlyou2 小时前
VS Code 右键菜单修复记录
前端
PILIPALAPENG2 小时前
Python 语法速成指南:前端开发者视角(JS 类比版)
前端·人工智能·python
JYeontu2 小时前
轮播图不够惊艳?试下这个立体卡片轮播图
前端·javascript·css
张就是我1065922 小时前
从前端角度理解 CVE-2026-31431
前端
AGoodrMe2 小时前
swift基础之async/await
前端·ios