[vue3] Element Plus 入门使用

 ✨✨个人主页:沫洺的主页

📚📚系列专栏: 📖 JavaWeb专栏📖 JavaSE专栏 📖 Java基础专栏📖vue3专栏 

                           📖MyBatis专栏📖Spring专栏📖SpringMVC专栏📖SpringBoot专栏

                           📖Docker专栏📖Reids专栏📖MQ专栏📖SpringCloud专栏     

💖💖如果文章对你有所帮助请留下三连✨✨

📅Element Plus

🎫Element Plus官网:Element Plus 

🎫Element-UI和Element-Plus的区别

  • 📌Element-UI: 基于vue2版本,对应Element2:基本不支持手机版
  • 📌Element-Plus: 基于vue3版,对应Element3:组件布局考虑了手机版展示

🎃安装

🎈 npm install element-plus --save

🎃全局安装图标

🎈 npm install @element-plus/icons-vue

🎃main.ts 使用 ElementPlus插件

import { createApp } from 'vue'

import App from './App.vue'

//引入路由文件
import router from './router/index'
//导入store
import store from './store/index'
//使用ElementPlus插件
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

//使用路由组件
const app=createApp(App)
//全局导入Element图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }
//使用ElementPlus插件
app.use(ElementPlus)
app.use(router)
//使用store
app.use(store)
app.mount('#app')

🎃Element Plus入门使用

分别将标签template和script中的代码复制到自己的.vue文件中

<template>
    商品列表子页
    <el-row class="mb-4">
    <el-button>Default</el-button>
    <el-button type="primary">Primary</el-button>
    <el-button type="success">Success</el-button>
    <el-button type="info">Info</el-button>
    <el-button type="warning">Warning</el-button>
    <el-button type="danger">Danger</el-button>
  </el-row>

  <el-row class="mb-4">
    <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>
  </el-row>

  <el-row class="mb-4">
    <el-button round>Round</el-button>
    <el-button type="primary" round>Primary</el-button>
    <el-button type="success" round>Success</el-button>
    <el-button type="info" round>Info</el-button>
    <el-button type="warning" round>Warning</el-button>
    <el-button type="danger" round>Danger</el-button>
  </el-row>

  <el-row>
    <el-button :icon="Search" circle />
    <el-button type="primary" :icon="Edit" circle />
    <el-button type="success" :icon="Check" circle />
    <el-button type="info" :icon="Message" circle />
    <el-button type="warning" :icon="Star" circle />
    <el-button type="danger" :icon="Delete" circle />
  </el-row>
</template>
<script setup lang="ts">
import {
  Check,
  Delete,
  Edit,
  Message,
  Search,
  Star,
} from '@element-plus/icons-vue'
</script>

Table表格

<template>
   <el-table :data="tableData" style="width: 100%" >
    <el-table-column prop="date" label="Date" width="180" />
    <el-table-column prop="name" label="Name" width="180" />
    <el-table-column prop="address" label="Address" />
    </el-table>
</template>
<script setup lang="ts">
const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
</script>

🎃效果

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue3 Element Plus 是一个基于 Vue3 的 UI 组件库,提供了丰富的组件和功能,用于开发 Web 应用程序。国际化是一个重要的功能,它允许用户在不同的语言环境下使用应用程序。 Vue3 Element Plus 提供了国际化的支持,使开发者能够轻松地将应用程序本地化为不同的语言。具体使用步骤如下: 首先,需要安装 Element Plus 和其相关的国际化依赖。 然后,在 Vue3 的入口文件中,使用 `createApp` 函数创建 Vue3 实例,并将国际化插件引入。例如,可以使用 `createI18n` 函数创建一个国际化实例: ``` import { createApp } from 'vue' import { createI18n } from 'vue-i18n' import ElementPlus from 'element-plus' const app = createApp(App) const i18n = createI18n({ locale: 'zh', messages: { // 导入各种语言的翻译文件 zh: require('./locales/zh.json'), en: require('./locales/en.json') } }) app.use(ElementPlus) app.use(i18n) app.mount('#app') ``` 在上面的代码中,`locale` 属性指定了默认的语言环境,`messages` 属性指定了各种语言对应的翻译文件。 接下来,在组件中使用 Element Plus 的国际化功能。例如,可以使用 `el-button` 组件的 `i18n` 属性来实现按钮的国际化: ``` <template> <el-button :i18n="t('button.text')"></el-button> </template> <script> import { useI18n } from 'vue-i18n' export default { setup() { const { t } = useI18n() return { t } } } </script> ``` 在上面的代码中,`t` 函数用于获取翻译后的文本内容,并将其赋值给按钮的 `i18n` 属性。 总而言之,Vue3 Element Plus 的国际化使用起来非常简便,只需要配置好相应的翻译文件,并在组件中使用相应的国际化函数即可实现界面的国际化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沫洺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值