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检测

相关推荐
崇山峻岭之间几秒前
C++ Prime Plus 学习笔记028
c++·笔记·学习
一个小小开发12 分钟前
在大型项目中为什么更推荐Composition API?它解决了哪些工程化问题?
vue.js
四眼肥鱼15 分钟前
全网最全的 qiankun 基于 react18+(主应用)、vue3.4+(微应用)实现页签缓存,页面缓存
前端·javascript
dorisrv17 分钟前
优雅地处理前端错误边界
前端
我的xiaodoujiao20 分钟前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 31--开源电商商城系统项目实战--加入购物车、提交订单测试场景
python·学习·测试工具·pytest
狗哥哥20 分钟前
Pinia Store 平滑迁移:用代理模式实现零风险重构
前端·架构
小菜鸟派大星20 分钟前
电路学习(九)MOS管
学习·硬件·mos管·电路·电路仿真
点云SLAM23 分钟前
Discrepancy 英文单词学习
人工智能·学习·英文单词学习·雅思备考·discrepancy·不一致、不协调·矛盾
老前端的功夫30 分钟前
前端水印技术深度解析:从基础实现到防破解方案
开发语言·前端·javascript·前端框架
立志成为大牛的小牛31 分钟前
数据结构——五十三、处理冲突的方法——拉链法(王道408)
数据结构·学习·考研·算法