【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

相关推荐
liangshanbo12158 分钟前
Webpack的分包策略面试题
前端·webpack·node.js
ttwuai14 分钟前
Golang Web后台管理框架推荐:Gin、GoFrame与数据面板项目怎么分
前端·golang·gin
广州华水科技14 分钟前
北斗GNSS变形监测系统在水库安全监测中的应用与优势
前端
276695829233 分钟前
youdao/有道翻译APP 算法协议分析
开发语言·前端·python·sign·youdao·有道翻译app算法·有道app协议请求
奕鼎竜瑆8 小时前
Solid 前端响应式开发从零到精通
前端·人工智能
动恰客流统计9 小时前
景区客流统计怎么做?兼顾管控与运营的实施方案解析
大数据·前端·人工智能
派小心.10 小时前
A/B测试工具免费版够用吗?
前端·数据分析
前端snow10 小时前
ai agent --- redis 缓存
前端
duanshu_11 小时前
官网表单与下载异常怎么排查?五个环节定位故障
前端·自动化·flyweight
Zhou14113611 小时前
SpringBoot_03_Web开发
前端·spring boot·python