使用vue开发项目,用到elementUI,根据官网的写法,我们可以自定义主题来适应我们的项目要求,下面来介绍一下两种方法实现的具体步骤,(可以参考官方文档自定义主题官方文档),先说项目中没有使用scss编写,用主题工具的方法(使用的较多)

第一种方法:使用命令行主题工具

使用vue-cli安装完项目并引入element-ui(具体可参考第二种方法中的介绍)

一、安装工具

1,安装主题工具

npm i element-theme -g

2,安装chalk主题,可以从 npm 安装或者从 GitHub 拉取最新代码

# 从 npm
npm i element-theme-chalk -D # 从 GitHub
npm i https://github.com/ElementUI/theme-chalk -D

二、初始化变量文件

et -i [可以自定义变量文件,默认为element-variables.scss]

> ✔ Generator variables file

这时根目录下会产生element-variables.scss(或自定义的文件),大致如下:

$--color-primary: #409EFF !default;
$--color-primary-light-1: mix($--color-white, $--color-primary, 10%) !default; /* 53a8ff */
$--color-primary-light-2: mix($--color-white, $--color-primary, 20%) !default; /* 66b1ff */
$--color-primary-light-3: mix($--color-white, $--color-primary, 30%) !default; /* 79bbff */
$--color-primary-light-4: mix($--color-white, $--color-primary, 40%) !default; /* 8cc5ff */
$--color-primary-light-5: mix($--color-white, $--color-primary, 50%) !default; /* a0cfff */
$--color-primary-light-6: mix($--color-white, $--color-primary, 60%) !default; /* b3d8ff */
$--color-primary-light-7: mix($--color-white, $--color-primary, 70%) !default; /* c6e2ff */
$--color-primary-light-8: mix($--color-white, $--color-primary, 80%) !default; /* d9ecff */
$--color-primary-light-9: mix($--color-white, $--color-primary, 90%) !default; /* ecf5ff */ $--color-success: #67c23a !default;
$--color-warning: #eb9e05 !default;
$--color-danger: #fa5555 !default;
$--color-info: #878d99 !default; ..

三、修改变量

直接编辑 element-variables.scss 文件,例如修改主题色为自己所需要的颜色(如: 紫色(purple))

$--color-primary: purple;

四、编译主题

修改完变量后,要编译主题(如果编译后,再次修改了变量,需要重新编译)

et

> ✔ build theme font
> ✔ build element theme

五、引入自定义主题

最后一步,将编译好的主题文件引入项目(编译的文件默认在根目录下的theme文件下,也可以通过 -o 参数指定打包目录),在入口文件main.js中引入

import '../theme/index.css'
import ElementUI from 'element-ui'
import Vue from 'vue' Vue.use(ElementUI)

在项目中写些样式,看下主题色是否改变:(主题色变为紫色)

<div>
<el-button>默认按钮</el-button>
<el-button type="primary">主要按钮</el-button>
<el-button type="success">成功按钮</el-button>
<el-button type="info">信息按钮</el-button>
<el-button type="warning">警告按钮</el-button>
<el-button type="danger">危险按钮</el-button>
</div>

第二种方法: 直接修改element样式变量

在项目中直接修改element的样式变量,(前提是你的文档也是使用scss编写)

一、首先用vue-cli安装一个新项目:

1,安装vue:

npm i -g vue

2,在项目目录下安装vue-cli:

npm i -g vue-cli

3,基于webpack建立新项目( vue-project)

vue init webpack vue-project

4,依次输入以下命令行,运行vue-project

cd vue-project
npm i
npm run dev

二、安装elementUI以及sass-loader,node-sass(项目中使用scss编写需要依赖的插件)

1,安装element-ui

npm i element-ui -S

2,安装sass-loader,node-sass

npm i sass-loader node-sass -D

在这里说一下,不需要配置webpack.base.conf.js文件,vue-loader会根据不同类型文件来配置相应loader来打包我们的样式文件(感兴趣的可看下vue-loader的核心代码)

三、改变element样式变量

1.在src下建立element-variables.scss文件(名字可以自定义),写入如下代码:

/* 改变主题色变量 */
$--color-primary: teal; /* 改变 icon 字体路径变量,必需 */
$--font-path: '../node_modules/element-ui/lib/theme-chalk/fonts'; @import "../node_modules/element-ui/packages/theme-chalk/src/index";

2.在入口文件main.js中引入上面的文件即可

import Vue from 'vue'
import Element from 'element-ui'
import './element-variables.scss' Vue.use(Element)

看下效果吧,在文件里引入些样式看看,如button

<div>
<el-button>默认按钮</el-button>
<el-button type="primary">主要按钮</el-button>
<el-button type="success">成功按钮</el-button>
<el-button type="info">信息按钮</el-button>
<el-button type="warning">警告按钮</el-button>
<el-button type="danger">危险按钮</el-button>
</div>

默认的颜色已经变为我们自定义的了,有其他的改变在element-variable.scss文件中改变变量即可

 

.

Vue的elementUI实现自定义主题的更多相关文章

  1. nuxt按需引入 element-UI、自定义主题色(终极按需引入)

    首先你要知道 nuxt.js怎么引入第三方插件 : 不多BB. 一.按需引入element-UI 第一步:安装 babel-plugin-component: npm install babel-pl ...

  2. element-ui修改自定义主题

    官方文档:https://element.eleme.cn/#/zh-CN/component/custom-theme 简单更换主题色 打开:在线主题编辑器,仅修改主题色,点击右上角[切换主题色], ...

  3. 在 vue-cli 项目中 使用elementUI 的“自定义主题”功能

    1.安装elementUI $ npm i element-ui -S 2.安装主题工具 npm i element-theme -g 3.安装chalk主题 npm 安装 npm i element ...

  4. 关于vue cli 使用iview 自定义主题遇到的坑

    定制主题,这里讲变量覆盖 当你老老实实的把上面文档中的代码一一复制粘贴到项目文件中时,发现了还没装less,所以你就 npm install less –savenpm install less-lo ...

  5. vue中使用element-ui自定义主题后,vue-cli跑不起来了

    环境:vue-cli 2.x版本 自己在官网配置了主题并放到了项目中https://element.eleme.cn/#/zh-CN/theme 然后,我的脚手架在我的电脑中休息了几天,就跑不通了呢! ...

  6. element 如何自定义主题

    自定义主题 在我学习element的时候,就直接忽略了.现在返回来学习一下 ,原来 通过自定义主题可以改变elemnt中默认的一些样式.这样,对于一些不想用elment自带但是用到比较多的样式,可以进 ...

  7. vue2.0-基于elementui换肤[自定义主题]

    0. 直接上 预览链接 vue2.0-基于elementui换肤[自定义主题] 1. 项目增加主题组件 在项目的src/components下添加skin文件夹 skin文件获取地址 2. 项目增加自 ...

  8. vue-基于elementui自定义主题更换皮肤及自定义内容的皮肤跟换

    参考这篇博客https://blog.csdn.net/young_Emily/article/details/78591261做一遍,加上自己的一些理解 思路:通过自己上一篇博客https://ww ...

  9. Element-UI自定义主题

    Element-UI自定义主题 1.介绍:我们可以自定义样式去覆盖element-ui的默认样式 // 在项目目录中新建 element-variables.scss 文件 // 上面为修改的变量 $ ...

随机推荐

  1. 《剑指offer》面试题5—从尾到头打印链表

    重要思路: 这个问题肯定要遍历链表,遍历链表的顺序是从头到尾,而要输出的顺序却是从尾到头,典型的“后进先出”,可以用栈实现. 注意stl栈的使用,遍历stack的方法. #include <io ...

  2. tableView刷新指定的cell 或section和滚动到指定的位置

    转自:http://blog.csdn.net/tianyou_code/article/details/54426494 //一个section刷新 NSIndexSet *indexSet=[[N ...

  3. Unity3D研究院之IOS&Android收集Log文件(六十二)

    开发项目的时候尤其在处理与服务器交互这块,如果服务端程序看不到客户端请求的Log信息,那么无法修改BUG.在Windows上Unity会自动讲Log文件写入本地,但是在IOS和Android上确没有这 ...

  4. Matplotlib 在绘画bar时, 鼠标响应点击 bar 的消息

    官方教程: http://urania.udea.edu.co/sitios/astronomia-2.0/pages/descargas.rs/files/descargasdt5vi/Cursos ...

  5. jzoj5987. 【WC2019模拟2019.1.4】仙人掌毒题 (树链剖分+概率期望+容斥)

    题面 题解 又一道全场切的题目我连题目都没看懂--细节真多-- 先考虑怎么维护仙人掌.在线可以用LCT,或者像我代码里先离线,并按时间求出一棵最小生成树(或者一个森林),然后树链剖分.如果一条边不是生 ...

  6. [HNOI2010] 弹飞绵羊 bounce

    标签:分块.题解: 200000,而且标号从0开始,很符合分块的条件啊.看看怎么实现. 首先分成√n个区间,然后如果我们对于每一个位置i,求出一个Next[i]和step[i],分别表示跳到的后一个位 ...

  7. [Xcode 实际操作]七、文件与数据-(22)使用OCR光学字符识别技术识别银行卡号码

    目录:[Swift]Xcode实际操作 本文将演示如何使用光学字符识别技术,识别信用卡上的卡号. OCR技术是光学字符识别的缩写(Optical Character Recognition), 是通过 ...

  8. android webview.goback 问题

    重写 shouldOverrideUrlLoading 不需要实现 view.loadUrl(url);直接return false;即可 如果实现了,则使用window.location.repla ...

  9. mysql count 中使用case when 带条件及去重

    SELECT CASE (SELECT NOW() > '2019-02-12 16:48:00') WHEN 1 THEN '男' WHEN 2 THEN '女' ELSE '未知' END ...

  10. python使用C扩展

    CPython还为开发者实现了一个有趣的特性,使用Python可以轻松调用C代码 开发者有三种方法可以在自己的Python代码中来调用C编写的函数-ctypes,SWIG,Python/C API.每 ...