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

相关推荐
柏箱几秒前
使用JavaScript写一个网页端的四则运算器
前端·javascript·css
TU^1 分钟前
C语言习题~day16
c语言·前端·算法
计算机学姐17 分钟前
基于微信小程序的调查问卷管理系统
java·vue.js·spring boot·mysql·微信小程序·小程序·mybatis
地球空间-技术小鱼17 分钟前
嵌入式系统学习
嵌入式硬件·学习
学习使我快乐013 小时前
JS进阶 3——深入面向对象、原型
开发语言·前端·javascript
bobostudio19953 小时前
TypeScript 设计模式之【策略模式】
前端·javascript·设计模式·typescript·策略模式
黄尚圈圈4 小时前
Vue 中引入 ECharts 的详细步骤与示例
前端·vue.js·echarts
浮华似水5 小时前
简洁之道 - React Hook Form
前端
dengqingrui1236 小时前
【树形DP】AT_dp_p Independent Set 题解
c++·学习·算法·深度优先·图论·dp