【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

相关推荐
大怪v9 小时前
AI抢饭?前端佬:我要验牌!
前端·人工智能·程序员
新酱爱学习9 小时前
字节外包一年,我的技术成长之路
前端·程序员·年终总结
小兵张健10 小时前
开源 playwright-pool 会话池来了
前端·javascript·github
IT_陈寒12 小时前
Python开发者必知的5大性能陷阱:90%的人都踩过的坑!
前端·人工智能·后端
codingWhat13 小时前
介绍一个手势识别库——AlloyFinger
前端·javascript·vue.js
代码老中医13 小时前
2026年CSS彻底疯了:这6个新特性让我删掉了三分之一JS代码
前端
不会敲代码113 小时前
Zustand:轻量级状态管理,从入门到实践
前端·typescript
踩着两条虫13 小时前
VTJ.PRO 双向代码转换原理揭秘
前端·vue.js·人工智能
扉川川13 小时前
OpenClaw 架构解析:一个生产级 AI Agent 是如何设计的
前端·人工智能
远山枫谷13 小时前
一文理清页面/组件通信与 Store 全局状态管理
前端·微信小程序