VUE3 学习笔记(13):VUE3 下的Element-Plus基本使用

UI是页面的门面,一个好的UI自然令人赏心悦目;国人团队开发的ElementUI在众多UI中较为常见,因此通过介绍它的使用让大家更好的了解第三方UI的使用。

安装

Npm install element-plus --save

Cnpm install element-plus --save

配置

全局配置(完整)

main.js

import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
// 全局element-plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

const app = createApp(App)

app.use(createPinia())
app.use(router)
//启用element-plus
app.use(ElementPlus)

app.mount('#app')

使用

app.vue

<script setup>
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from './components/HelloWorld.vue'
</script>

<template>
  <header>
    <img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />

    <div class="wrapper">
      <HelloWorld msg="You did it!" />

      <nav>
        <RouterLink to="/">Home</RouterLink>
        <RouterLink to="/about">About</RouterLink>
      </nav>
    </div>
  </header>
  <RouterView />
  <div 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>
  </div>
</template>

效果

字体图标配置

安装字体图标

npm install @element-plus/icons-vue

配置

main.js

import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
// 全局element-plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
//全局引用图标字体
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)

app.use(createPinia())
app.use(router)
//启用element-plus
app.use(ElementPlus)
//启用图标字体
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.mount('#app')

使用

<script setup>
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from './components/HelloWorld.vue'
//导入图标
import {Edit} from "@element-plus/icons-vue";
</script>

<template>
  <header>
    <img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />
    <div 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-icon :size="90" color="red">
        <Edit />
      </el-icon>
    </div>

    <div class="wrapper">
      <HelloWorld msg="You did it!" />

      <nav>
        <RouterLink to="/">Home</RouterLink>
        <RouterLink to="/about">About</RouterLink>
      </nav>
    </div>
  </header>
  <RouterView />

</template>

效果

相关推荐

  1. vue3+element-plus国际化

    2024-06-11 02:08:01       8 阅读
  2. 基于Vue2与3版本Element UI与Element Plus入门

    2024-06-11 02:08:01       9 阅读
  3. UI 神器 - Vue3 中如何使用 element-plus

    2024-06-11 02:08:01       20 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-11 02:08:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-11 02:08:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-11 02:08:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-11 02:08:01       20 阅读

热门阅读

  1. 题解web

    题解web

    2024-06-11 02:08:01      9 阅读
  2. 在 React 应用中,怎么封装一个路由权限

    2024-06-11 02:08:01       9 阅读
  3. PHP小方法

    2024-06-11 02:08:01       12 阅读
  4. 课时151:项目发布_基础知识_技术要点

    2024-06-11 02:08:01       10 阅读
  5. C++设计模式---策略模式

    2024-06-11 02:08:01       11 阅读
  6. Permissions 0644 for ‘/home/jsy/.ssh/id_rsa‘ are too open

    2024-06-11 02:08:01       12 阅读
  7. Qt Graphics View Framework 简介

    2024-06-11 02:08:01       10 阅读
  8. CentOS 7 安装配置基础DNS服务,主从域名服务器

    2024-06-11 02:08:01       13 阅读
  9. 【OS】AUTOSAR OS调度器实现原理

    2024-06-11 02:08:01       11 阅读
  10. 智能合约中外部调用漏洞

    2024-06-11 02:08:01       9 阅读
  11. ovs网络配置命令

    2024-06-11 02:08:01       8 阅读
  12. TypeScript基础教程学习

    2024-06-11 02:08:01       11 阅读
  13. ⑤单细胞学习-cellchat组间通讯差异分析

    2024-06-11 02:08:01       11 阅读
  14. Spring和SpringBoot的特点

    2024-06-11 02:08:01       12 阅读
  15. json数据解析

    2024-06-11 02:08:01       7 阅读
  16. 大学生如何学习C语言编程?

    2024-06-11 02:08:01       10 阅读
  17. Y2期末测试

    2024-06-11 02:08:01       7 阅读