VUE3项目学习系列--element-plus集成(三)

1、安装依赖

Element-plus官网:快速开始 | Element Plus (element-plus.org)

javascript 复制代码
pnpm i element-plus

在项目main.ts中引入element-plus:

javascript 复制代码
import { createApp } from "vue";
import App from "./App.vue";
// 从Element官网上参考,引入element-plus插件与样式
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

const app = createApp(App)

// 挂载到应用上
app.use(ElementPlus)
app.mount('#app')

在app.vue中使用element-plus:

javascript 复制代码
<script setup lang="ts">
</script>

<template>
  <div>
    <!-- element-plus按钮 -->
    <el-button type="primary" size="de">测试</el-button>
    <el-button plain>Plain</el-button>
    <el-button type="primary" plain>Primary</el-button>
    <el-button type="success" plain>Success</el-button>
    <el-button type="info" plain>Info</el-button>
    <el-button type="warning" plain>Warning</el-button>
    <el-button type="danger" plain>Danger</el-button>
   <h1>VUE3</h1>
  </div>
</template>

<style scoped>

</style>

运行启动项目:pnpm run dev

2、安装element 图标库

复制代码
pnpm i @element-plus/icons-vue

在app.vue页面中使用图标:先引入图标Plus,再在控件按钮中使用图标:icon="Plus"

html 复制代码
<script setup lang="ts">
  // 引入图标
  import {Plus} from "@element-plus/icons-vue"
</script>

<template>
  <div>
    <!-- element-plus按钮 -->
    <el-button type="primary" size="de" :icon="Plus">测试</el-button>
    <el-button plain>Plain</el-button>
    <el-button type="primary" plain>Primary</el-button>
    <el-button type="success" plain>Success</el-button>
    <el-button type="info" plain>Info</el-button>
    <el-button type="warning" plain>Warning</el-button>
    <el-button type="danger" plain>Danger</el-button>
   <h1>VUE3</h1>
  </div>
</template>

<style scoped>

</style>

3、element-plus 国际化

由于element-plus模式显示的英文,在使用控件过程中要求显示中文需要在main.ts如下配置

javascript 复制代码
import { createApp } from "vue";
import App from "./App.vue";
// 从Element官网上参考,引入element-plus插件与样式
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 配置element-plus国际化
//@ts-ignore --忽略ts校验
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
const app = createApp(App)

app.use(ElementPlus, {
    locale: zhCn,
  })
// 挂载到应用上
app.use(ElementPlus)
app.mount('#app')

需要注意的是:'element-plus/dist/locale/zh-cn.mjs'引入后会报红,是由于ts校验检测导致的,通过添加://@ts-ignore 可忽略ts检测

相关推荐
幼儿园技术家5 分钟前
Uniapp简易使用canvas绘制分享海报
前端
开开心心就好1 小时前
免费PDF处理软件,支持多种操作
运维·服务器·前端·spring boot·智能手机·pdf·电脑
全宝1 小时前
🎨前端实现文字渐变的三种方式
前端·javascript·css
Green1Leaves1 小时前
pytorch学习-9.多分类问题
人工智能·pytorch·学习
yanlele1 小时前
前端面试第 75 期 - 2025.07.06 更新前端面试问题总结(12道题)
前端·javascript·面试
妮妮喔妮2 小时前
【无标题】
开发语言·前端·javascript
慕y2742 小时前
Java学习第十五部分——MyBatis
java·学习·mybatis
谦行2 小时前
深度神经网络训练过程与常见概念
前端
Simon_He2 小时前
一个免费的在线压缩网站超越了付费的压缩软件
前端·开源·图片资源
碣石潇湘无限路2 小时前
【AI篇】当Transformer模型开始学习《孙子兵法》
人工智能·学习