element-plus自定义主题不生效

element-plus自定义主题不生效

问题原因

  1. 当我们按照element的文档配置后不生效
    2.解决办法:
    当我们配置vite.cofnig.ts时
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import ViteImages from "vite-plugin-vue-images";
import {
  ElementPlusResolver,
  VantResolver,
} from "unplugin-vue-components/resolvers";
import {
  createStyleImportPlugin,
  ElementPlusResolve,
} from "vite-plugin-style-import";
import * as path from "path";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    //配置自动导入element start
    AutoImport({
      resolvers: [
        ElementPlusResolver({
          // 自动引入修改主题色添加这一行,使用预处理样式,不添加将会导致使用ElMessage,ElNotification等组件时默认的主题色会覆盖自定义的主题色
          importStyle: "sass",
        }),
      ],
    }),
    Components({
      resolvers: [
        ElementPlusResolver({
          // 自动引入修改主题色添加这一行,使用预处理样式
          importStyle: "sass",
        }),
        VantResolver(),
      ],
    }),
    createStyleImportPlugin({
      resolves: [ElementPlusResolve()],
      libs: [
        {
          libraryName: "element-plus",
          esModule: true,
          resolveStyle: (name: string) => {
            return `element-plus/theme-chalk/${name}.css`;
          },
        },
      ],
    }),
  //配置@符
  resolve: {
    alias: {
      "@": path.join(__dirname, "src"),
      "#": path.join(__dirname, "types"),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/css/element/index.scss" as *;`,
      },
    },
  },
});
posted @ 2022-10-01 22:46  xiaowei123456  阅读(3429)  评论(0编辑  收藏  举报