当前位置:   article > 正文

Vue3+vite+element-plus修改主题颜色_修改 elemmentplus var 颜色

修改 elemmentplus var 颜色

怎么引入使用这边就不多说了

自定义element-plus主题色

1.在项目中安装sass 

npm install sass 

2.新建scss文件:src/styles/element/index.scss

  1. // @/styles/element/index.scss
  2. @forward "element-plus/theme-chalk/src/common/var.scss" with ($colors: (
  3. "primary": ("base": #0052D9),
  4. "success": ("base": #67c23a),
  5. "warning": ("base": #e6a23c),
  6. "danger": ("base": #E34D59),
  7. "error": ("base": #E34D59),
  8. "info": ("base": #E7E7E7),
  9. )
  10. );

3.vite.config.js配置

  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import * as path from 'path';
  4. import AutoImport from 'unplugin-auto-import/vite'
  5. import Components from 'unplugin-vue-components/vite'
  6. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  7. import {createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import';
  8. // https://vitejs.dev/config/
  9. export default defineConfig(({mode}) => {
  10. const config = loadEnv(mode, './')
  11. return {
  12. resolve: {
  13. alias: {
  14. '@': path.resolve(__dirname, 'src'),
  15. "_C":path.resolve(__dirname,"src/components"),
  16. "views": path.resolve(__dirname, "src/views")
  17. }
  18. },
  19. css: {
  20. preprocessorOptions: {
  21. scss: {
  22. // 自定义的主题色
  23. additionalData: `@use "@/styles/element/index.scss" as *;`,
  24. },
  25. },
  26. },
  27. plugins: [
  28. //配置自动导入element start
  29. createStyleImportPlugin({
  30. resolves: [ElementPlusResolve()],
  31. libs: [
  32. {
  33. libraryName: 'element-plus',
  34. esModule: true,
  35. resolveStyle: (name: string) => {
  36. return `element-plus/theme-chalk/${name}.css`
  37. },
  38. },
  39. ]
  40. }),
  41. //配置自动导入element end
  42. vue(),
  43. // 自动引入
  44. AutoImport({
  45. resolvers: [ElementPlusResolver({
  46. // 自动引入修改主题色添加这一行,使用预处理样式,不添加将会导致使用ElMessage,ElNotification等组件时默认的主题色会覆盖自定义的主题色
  47. importStyle: "sass",
  48. })],
  49. }),
  50. Components({
  51. resolvers: [ElementPlusResolver({
  52. // 自动引入修改主题色添加这一行,使用预处理样式
  53. importStyle: "sass",
  54. })],
  55. })
  56. ],
  57. server: {
  58. open: true,
  59. proxy: {
  60. '/api': {
  61. target: config.VITE_BASE_URL,
  62. changeOrigin: true,
  63. rewrite: (path) => path.replace(/\/api/, '') //正则匹配替换
  64. },
  65. '/uploads': {
  66. target: config.VITE_BASE_URL,
  67. changeOrigin: true,
  68. rewrite: (path) => path.replace(/\/uploads/, '') //正则匹配替换
  69. }
  70. },
  71. hmr: true, // 热更新是否开启
  72. },
  73. build: {
  74. assetsDir: './static/front/'
  75. }
  76. }
  77. })

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/133464?site
推荐阅读
相关标签
  

闽ICP备14008679号