首页 / 知识
Vue的elementUI实现自定义主题
2023-04-11 15:08:00
第一种方法:使用命令行主题工具
使用vue-cli安装完项目并引入element-ui(具体可参考第二种方法中的介绍)
一、安装工具
1,安装主题工具
npmielement-theme-g
2,安装chalk主题,可以从npm安装或者从GitHub拉取最新代码
#从npm
npmielement-theme-chalk-D
#从GitHub
npmihttps://github.com/ElementUI/theme-chalk-D
二、初始化变量文件
et-i[可以自定义变量文件,默认为element-variables.scss]
>✔Generatorvariablesfile
这时根目录下会产生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
>✔buildthemefont
>✔buildelementtheme
五、引入自定义主题
最后一步,将编译好的主题文件引入项目(编译的文件默认在根目录下的theme文件下,也可以通过-o参数指定打包目录),在入口文件main.js中引入
import'../theme/index.css'
importElementUIfrom'element-ui'
importVuefrom'vue'
Vue.use(ElementUI)
在项目中写些样式,看下主题色是否改变:(主题色变为紫色)
<p>
<el-button>默认按钮</el-button>
<el-buttontype="primary">主要按钮</el-button>
<el-buttontype="success">成功按钮</el-button>
<el-buttontype="info">信息按钮</el-button>
<el-buttontype="warning">警告按钮</el-button>
<el-buttontype="danger">危险按钮</el-button>
</p>
第二种方法:直接修改element样式变量
在项目中直接修改element的样式变量,(前提是你的文档也是使用scss编写)
一、首先用vue-cli安装一个新项目:
1,安装vue:
npmi-gvue
2,在项目目录下安装vue-cli:
npmi-gvue-cli
3,基于webpack建立新项目(vue-project)
vueinitwebpackvue-project
4,依次输入以下命令行,运行vue-project
cdvue-project
npmi
npmrundev
二、安装elementUI以及sass-loader,node-sass(项目中使用scss编写需要依赖的插件)
1,安装element-ui
npmielement-ui-S
2,安装sass-loader,node-sass
npmisass-loadernode-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中引入上面的文件即可
importVuefrom'vue'
importElementfrom'element-ui'
import'./element-variables.scss'
Vue.use(Element)
看下效果吧,在文件里引入些样式看看,如button
<p>
<el-button>默认按钮</el-button>
<el-buttontype="primary">主要按钮</el-button>
<el-buttontype="success">成功按钮</el-button>
<el-buttontype="info">信息按钮</el-button>
<el-buttontype="warning">警告按钮</el-button>
<el-buttontype="danger">危险按钮</el-button>
</p>
默认的颜色已经变为我们自定义的了,有其他的改变在element-variable.scss文件中改变变量即可
本文转载自中文网 |
最新内容
相关内容
python如何读取列表中元素的位置?
python如何读取列表中元素的位置?,位置,数据,异常,培训,字符串,元素,索引,方法,示例,结果,python读取列表中元素位置的方法:1、使用index()方python中获取路径的三种方法
python中获取路径的三种方法,工作,代码,情况,培训,下来,路径,文件,也就是,桌面,目录,python中获取路径总结下来分为三种情况:1、获取工作目录python如何调用另一个文件夹中的内
python如何调用另一个文件夹中的内容?,系统,培训,文件,模块,内容,路径,函数,所在,前缀,语句,python中调用另外一个文件夹中的内容:1、同一文件python怎么找出所有的数字?
python怎么找出所有的数字?,数字,培训,代码,小数点,小数,字符串,整数,表达式,含义,思路,python中获取字符串中所有数字的方法:1、使用正则表达如何在python代码中指定保存的文件
如何在python代码中指定保存的文件格式,代码,培训,文件格式,格式,二进制文件,文件,后缀,以上,方法,更多,python指定保存文件格式的方法:1、保Python如何复制文件中的内容
Python如何复制文件中的内容,盘中,数据,培训,文件,内容,方法,文件夹,路径,源文件,文件名,python复制文件中内容的方法:1、使用shutil.copyfile实数是不是python的数据类型?
实数是不是python的数据类型?,数字,标准,培训,实数,数据类型,数轴,复数,有限小数,无理数,虚数,实数是python的数据类型。实数,是有理数和无理linux下怎么查看python的包
linux下怎么查看python的包,软件,培训,工具,管理,命令,格式,详细信息,下面,以上,参数,linux中可以使用piplist命令查看安装的python包。pip是python中的open函数如何编码?
python中的open函数如何编码?,数据,系统,可取,培训,文件,参数,函数,时候,表示,模式,python中的open函数可以通过在打开文件时添加encoding参python读入不定行字符的问题
python读入不定行字符的问题,培训,字符,问题,方法,头尾,示例,空格,字符串,序列,结尾,python读入不定行字符的问题解决:stdin.readline()会读取python中的int是什么意思?
python中的int是什么意思?,数字,数据,培训,字符串,参数,语法,实例,以下,方法,函数,python中的int()函数用于将一个字符串或数字转换为整型。Python库与模块的区别是什么?
Python库与模块的区别是什么?,名称,概念,标准,机构,培训,名字,代码,模块,区别,函数,python库与模块的区别是:模块、库主要区别在于他们的定义