修改element Plus的主题样式

news2024/9/28 4:46:14

安装element plus 安装icon

pnpm install element-plus
pnpm install @element-plus/icons-vue

main.ts配置

icon的使用https://element-plus.gitee.io/zh-CN/component/icon.html#%E7%BB%93%E5%90%88-el-icon-%E4%BD%BF%E7%94%A8

import { createApp } from 'vue'
import './style.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 如果您正在使用CDN引入,请删除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.use(ElementPlus).mount('#app')

使用效果

在这里插入图片描述

<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 lang="ts" setup>
import {
  Check,
  Delete,
  Edit,
  Message,
  Search,
  Star,
} from '@element-plus/icons-vue'
</script>

修改element Plus主题

修改后的效果

在这里插入图片描述

HelloWorld.vue

<template>
  <h1 class="title">测试</h1>
  <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 lang="ts" setup>
import {
  Check,
  Delete,
  Edit,
  Message,
  Search,
  Star,
} from '@element-plus/icons-vue'
</script>
<style lang="scss" scoped>
  .title{
    color: red;
  }
</style>

#### mian.ts文件内容
```ts
import { createApp } from 'vue

import './assets/style/element-theme.scss'
import './style.css'
import ElementPlus from 'element-plus'
// import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.use(ElementPlus).mount('#app')

vite.config.ts

import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  // css: {
  //   preprocessorOptions: {
  //     //define global scss variable
  //     scss: {
  //       additionalData: `@import "@/theme/var.scss";`,
  //     }
  //   }
  // }
})

element-theme.scss

在这里插入图片描述

/* 只需要重写你需要的变量即可 */
@forward 'element-plus/theme-chalk/src/common/var.scss' with (
  $colors: (
    'primary': (
      'base': #000,
    ),
  ),
);

/* 如果只是按需导入,则可以忽略以下内容。
如果你想导入所有样式: */
/* 以上为官方说法  经验证 不应用以下代码 会使失去未重新定义的样式 */
@use "element-plus/theme-chalk/src/index.scss" as *;

package.json

{
  "name": "vite-demo-vue3",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "@element-plus/icons-vue": "^2.1.0",
    "element-plus": "^2.3.5",
    "sass": "^1.62.1",
    "vue": "^3.2.47"
  },
  "devDependencies": {
    "@types/node": "^20.2.5",
    "@vitejs/plugin-vue": "^4.1.0",
    "typescript": "^5.0.2",
    "vite": "^4.3.2",
    "vue-tsc": "^1.4.2"
  }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/586750.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

用chatGPT来NEW个对象让“码农”的节日不再仅仅只有1024(赶鸭子上架式的成长、无效不得不立的flag)

用chatGPT来NEW个对象让“码农”的节日不再仅仅只有1024 前言一、大部分的成长都是赶鸭子上架二、节日是为了告诉自己不孤单三、做不到也要立下的flag四、New个对象吧1.php定义一个科技工作者形象2.python定义一个科技工作者形象3.javascript定义一个科技工作者形象 总结 前言 …

Docker的简单使用

文章目录 Docker的简单使用Docker 是什么Docker的基本组成镜像&#xff08;image&#xff09;容器&#xff08;container&#xff09;仓库&#xff08;repository&#xff09; 安装Docker卸载docker配置docker镜像加速Docker的常用命令docker安装nginx&#xff08;docker简单使…

chatgpt赋能python:Python中升序排序详解

Python中升序排序详解 什么是升序排序&#xff1f; 升序排序指的是按照从小到大的顺序排列数组、列表等数据类型。在Python中&#xff0c;可以使用各种函数和方法来对数据进行升序排序&#xff0c;例如sort()函数、sorted()函数、和lambda表达式等。下面将详细介绍这些方法。…

Leaflet基本用法

使用 阿里云地理工具 获取相应的地理JSON数据&#xff0c;用于对地图边界绘制。 如何使用leaflet&#xff1f; 这里用HTML5进行操作&#xff1b; 因为我是用的是Leaflet库&#xff0c;所以要引入JavaScript 和 CSS 文件&#xff08;可参考官网https://leafletjs.com/&#x…

chatgpt赋能python:Python中常用的内置函数

Python中常用的内置函数 Python是一门非常强大的编程语言&#xff0c;它有很多内置函数可以帮助开发人员更快速、更便捷地编写程序。在本文中&#xff0c;将会介绍并着重标记加粗一些常用的Python内置函数。 print() print()是Python中最基本也是最常用的内置函数之一&#…

【异常捕获】

异常捕获 异常概念处理错误方式 异常处理举例栈展开异常规范异常继承层次优缺点 异常 概念 异常时程序可能检测到的&#xff0c;运行时不正常的情况&#xff0c;如存储空间耗尽&#xff0c;数组越界等&#xff0c;可以预见可能发生在什么地方但不知道在什么时候发生的错误。 …

chatgpt赋能python:Python中如何更新pip:一篇详细指南

Python中如何更新pip&#xff1a;一篇详细指南 作为一个有10年Python编程经验的工程师&#xff0c;我很清楚更新pip的重要性。pip是Python的依赖管理工具&#xff0c;它可以帮助您轻松安装、升级和删除Python包。随着Python不断发展和更新&#xff0c;保持最新版本的pip也很重…

SCI 投稿论文入门 —— 2. 图片编辑(Visio / Origin)

目录 引言IEEE trans论文图片格式要求单栏图片双栏图片 论文中插入曲线图曲线图具体要求 论文中插入结构图曲线图与结构图结合visio中设置界面单栏单张图片曲线图中需要插入结构图 箭头&#xff0c;线段粗细设置字体下标 引言 由于特殊要求&#xff0c;需要用word版本进行编辑…

Springboot整合Swagger2(3.0.0版本)

天行健&#xff0c;君子以自强不息&#xff1b;地势坤&#xff0c;君子以厚德载物。 每个人都有惰性&#xff0c;但不断学习是好好生活的根本&#xff0c;共勉&#xff01; 文章均为学习整理笔记&#xff0c;分享记录为主&#xff0c;如有错误请指正&#xff0c;共同学习进步。…

SpringCloudAlibaba下篇(GateWay,Skywalking)(超级无敌认真好用,万字收藏篇!!!!)

文章目录 SpringCloudAlibaba下篇(GateWay,Skywalking)1 GateWay1.1 什么是网关1.2 GateWay介绍1.3 GataWay的基本使用1.4 GataWay整合Nacos1.5 断言路由工厂1.5.1 内置断言路由工厂1.5.2 自定义断言路由工厂 1.6 过滤器工厂1.6.1 内置局部过滤器工厂1.6.2 自定义局部过滤器1.6…

手撕code(2)

文章目录 1 设计模式1.1 单例模式1.1.1 懒汉单例1.1.2 饿汉单例1.1.3 总结 1.2 简单工厂模式 2 实现智能指针 1 设计模式 1.1 单例模式 某个类&#xff0c;不应该有多个实例&#xff0c;此时就可以使用单例模式。如果尝试创建多个实例&#xff0c;编译器就会报错。 1.1.1 懒…

【踩坑】mirai挂机运行经常自动退出怎么办?

转载请注明出处&#xff1a;小锋学长生活大爆炸[xfxuezhang.cn] 目录 背景介绍 解决思路 实现方法 最终效果 背景介绍 就是说&#xff0c;后台运行了mcl&#xff0c;但经常莫名其妙自动会退出&#xff0c;导致每次都得手动的去服务器上重新启动mcl。而对于自己运行的需要用…

“老年养生”APP的设计与开发

摘要&#xff1a;我国人口老龄化呈上升趋势&#xff0c;老年人口比重增加。这是我国经济发展的一大挑战&#xff0c;也是老年健康产业的一大机遇。随着我国经济发展&#xff0c;越来越多的人开始关注自己的身体&#xff0c;这导致各种关于健康的网络应用层出不穷。但是经过分析…

正则表达式与通配符 -- *?在正则表达式与通配符中的区别

1、前言 最近因为工作需要写一些自动化脚本&#xff0c;里面需要用到正则表达式来匹配特定的字符串&#xff0c;于是查了一些正则表达式相关的资料。资料里面都提到&#xff1a;*匹配前面的子表达式0次或任意多次。我当时就纳闷&#xff0c;*到底是表示的是匹配的次数还是可以…

2. JVM内存模型深度剖析与优化

JVM性能调优 1. JDK的体系结构2. Java语言的跨平台特性3.JVM整体结构及内存模型3.1 内存模型3.1.1 PC寄存器&#xff08;线程私有&#xff09;3.1.2 虚拟机栈&#xff08;线程私有&#xff09;1. 局部变量表2. 操作数栈 本文是按照自己的理解进行笔记总结&#xff0c;如有不正确…

SimpleCG绘图函数(3)--绘制矩形

前面我们已经学习了点和线的绘制,本篇我们继续绘图函数学习----矩形的绘制&#xff0c;也就是长方形的绘制,并给出一个绘制楼房的例子演示矩形的应用。 所有绘制矩形相关函数如下&#xff1a; //以下矩形左上角坐标(left, top)&#xff0c;右下角坐标(right,bottom ) //以线条…

跨境电商系统开发-电商商城系统平台定制方案

随着业务的拓展&#xff0c;不少企业开始将目光转向国外市场&#xff0c;那么如何定制一套属于想自己的跨境出海电商商城方案呢&#xff1f;需要做好以下关口把关&#xff1a; 欢迎名片交流探讨开发平台流程 买家端(h5/pc/app) www.mardao.cn 账号 密码 卖家端(h5/pc)…

八、(重点)视图集ModelViewSet自定义action路由routers

上一章&#xff1a; 七、Django DRF框架GenericAPIView--搜索&排序&分页&返回值_做测试的喵酱的博客-CSDN博客 下一章&#xff1a; 九、DRF生成API文档_做测试的喵酱的博客-CSDN博客 一、视图集ModelViewSet与ReadOnlyViesSet ModelViewSet视图集 与 ReadOnly…

基于FPGA:运动目标检测(包围盒仿真工程,及一些调试问题)

目录 前言一、安装器件库二、仿真工程操作1、进入文件列表2、找到bounding_box_locate.vt&#xff0c;双击打开文件3、修改路径4、路径设置5、切换回“Hierarchy”&#xff0c;即工程界面6、运行仿真7、查看波形 重点&#xff1a;调试问题三、仿真代码1、仿真顶层文件2、绘制包…

node篇-fs模块儿

nodejs-fs模儿 异步 1. mkdir() 创建一个目录 // 1.mkdir 创建一个目录&#xff0c;回调函数的参数含义&#xff1a;err const fs require(fs); fs.mkdir(./avater,(err)>{console.log(err);if(err && err.code EEXIST){console.log(当前目录已经存在)} }) 当我…