当前位置:   article > 正文

ElementPlus自定义主题色_element-plus 修改主题色

element-plus 修改主题色

官方案例地址:mirrors / element-plus / element-plus-vite-starter · GitCode

1.创建styles/element/index.scss文件

  1. // styles/element/index.scss
  2. /* 只需要重写你需要的即可 */
  3. @forward 'element-plus/theme-chalk/src/common/var.scss' with (
  4. $colors: (
  5. 'primary': (
  6. 'base': green,
  7. ),
  8. ),
  9. );

2.在vite.config.js文件中进行配置

  1. //vite.config.js
  2. import { fileURLToPath, URL } from 'node:url'
  3. import { defineConfig } from 'vite'
  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 vue from '@vitejs/plugin-vue'
  8. // https://vitejs.dev/config/
  9. export default defineConfig({
  10. plugins: [
  11. vue(),
  12. AutoImport({
  13. resolvers: [ElementPlusResolver()],
  14. }),
  15. Components({
  16. //1.配置elementPlus采用css样式文件
  17. resolvers: [ElementPlusResolver({importStyle: "sass",})],
  18. }),
  19. ],
  20. resolve: {
  21. alias: {
  22. '@': fileURLToPath(new URL('./src', import.meta.url))
  23. }
  24. },
  25. css: {
  26. preprocessorOptions: {
  27. scss: {
  28. // 自动导入定制化样式文件进行样式覆盖
  29. additionalData: `
  30. @use "@/styles/element/index.scss" as *;
  31. `,
  32. }
  33. }
  34. }
  35. })

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