当前位置:   article > 正文

vue3 element plus 更换主题颜色_elementplus修改主题色及皮肤设置的方法是什么

elementplus修改主题色及皮肤设置的方法是什么

实测有效

1.src下新建文件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': #b78e81,
  7. ),
  8. 'success': (
  9. 'base': #b78e81,
  10. ),
  11. ),
  12. );

2.vite.config.ts 里面新增依赖

  1. // 新增 npm i unplugin-vue-components
  2. // 新增 npm i unplugin-auto-import
  3. import AutoImport from "unplugin-auto-import/vite";
  4. import Components from "unplugin-vue-components/vite";
  5. import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

3.配置vite.config.ts 重新启动即可

  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import { resolve } 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. // https://vitejs.dev/config/
  8. const pathResolve = (dir: string) => {
  9. return resolve(__dirname, ".", dir);
  10. };
  11. const alias: Record<string, string> = {
  12. "/@": pathResolve("./src/"),
  13. };
  14. // vite.config
  15. export default defineConfig({
  16. plugins: [
  17. vue(),
  18. // 1.第一步
  19. AutoImport({
  20. resolvers: [ElementPlusResolver()],
  21. }),
  22. // 2.第二步
  23. Components({
  24. //1.配置elementPlus采用css样式文件
  25. resolvers: [ElementPlusResolver({ importStyle: "sass" })],
  26. }),
  27. ],
  28. resolve: { alias },
  29. css: {
  30. preprocessorOptions: {
  31. // 3.第三步
  32. scss: {
  33. // additionalData: `@import "./src/style/mixin.scss";`, // 此处全局的scss文件
  34. additionalData: `
  35. @use "/@/styles/element/index.scss" as *;
  36. `,
  37. },
  38. },
  39. },
  40. server: {
  41. proxy: {
  42. "/api": {
  43. target: "http://localhost:3000",
  44. changeOrigin: true,
  45. },
  46. },
  47. },
  48. });

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

闽ICP备14008679号