Vue3+vite+element-plus+Sass修改主題顏色

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

// @/styles/element/index.scss

@forward "element-plus/theme-chalk/src/common/var.scss" with ($colors: (

? ? ? ? "primary": ("base": #0052D9),

? ? ? ? "success": ("base": #67c23a),

? ? ? ? "warning": ("base": #e6a23c),

? ? ? ? "danger": ("base": #E34D59),

? ? ? ? "error": ("base": #E34D59),

? ? ? ? "info": ("base": #E7E7E7),

? ? )

2、vite.config.js配置

import { defineConfig } from 'vite'

import vue from '@vitejs/plugin-vue'

import WindiCSS from 'vite-plugin-windicss'

// import legacy from '@vitejs/plugin-legacy'

import { resolve } from 'path'

import compressPlugin from 'vite-plugin-compression'

import vueJsx from '@vitejs/plugin-vue-jsx'

import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

import AutoImport from "unplugin-auto-import/vite"

import Components from "unplugin-vue-components/vite"

import { ElementPlusResolver } from "unplugin-vue-components/resolvers"

// import ElementPlus from "unplugin-element-plus/vite"

import { createStyleImportPlugin, ElementPlusResolve } from "vite-plugin-style-import"

import * as path from 'path'

export default ({ mode }) => {

? console.log('mode:', mode)

? const isDevelopment = mode == 'development'

? const target = isDevelopment ? 'crm-dev' : 'crm'

? return defineConfig({

? ? resolve: {

? ? ? alias: {

? ? ? ? '@': resolve('./src'),

? ? ? ? '@img': resolve('./src/assets/image')

? ? ? }

? ? },

? ? css: {

? ? ? preprocessorOptions: {

? ? ? ? scss: {

? ? ? ? ? additionalData: '@use "@/assets/sass/globalstyle.scss" as *;'

? ? ? ? }

? ? ? }

? ? },

? ? plugins: [

? ? ? createStyleImportPlugin({

? ? ? ? resolves: [ElementPlusResolve()],

? ? ? ? libs: [

? ? ? ? ? {

? ? ? ? ? ? libraryName: 'element-plus',

? ? ? ? ? ? esModule: true,

? ? ? ? ? ? resolveStyle: (name: string) => {

? ? ? ? ? ? ? return `element-plus/theme-chalk/${name}.css`

? ? ? ? ? ? }

? ? ? ? ? }

? ? ? ? ]

? ? ? }),

? ? ? vue(),

? ? ? WindiCSS(),

? ? ? vueJsx(),

? ? ? AutoImport({

? ? ? ? imports: ["vue", "vue-router"], // 自動(dòng)導(dǎo)入vue和vue-router相關(guān)函數(shù)

? ? ? ? dts: "src/auto-import.d.ts",// 生成 `auto-import.d.ts` 全局聲明

? ? ? }),

? ? ? Components({

? ? ? ? resolvers: ElementPlusResolver({

? ? ? ? ? importStyle: 'sass'

? ? ? ? })

? ? ? }),

? ? ? compressPlugin({

? ? ? ? deleteOriginFile: true,

? ? ? ? disable: true, ?// 禁用壓縮

? ? ? }),

? ? ? createSvgIconsPlugin({

? ? ? ? // 指定需要緩存的圖標(biāo)文件夾

? ? ? ? iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],

? ? ? ? // 指定symbolId格式

? ? ? ? symbolId: 'icon-[dir]-[name]',

? ? ? }),

? ? ? // legacy({

? ? ? // ? targets: ['defaults', 'not IE 11']

? ? ? // })

? ? ],

? ? // base: 'https://crm-dev.fangxiaobao.net/pc_frontend_assets/',

? ? base: isDevelopment ? '/' : '/pc_frontend_assets',

? ? build: {

? ? ? manifest: true,

? ? ? minify: 'terser',

? ? ? assetsDir: '',

? ? ? terserOptions: {

? ? ? ? compress: {

? ? ? ? ? // drop_console: true,

? ? ? ? ? // drop_debugger: true,

? ? ? ? },

? ? ? },

? ? },

? ? server: {

? ? ? port: 8088,

? ? ? host: '0.0.0.0',

? ? ? proxy: {

? ? ? ? '/api': {

? ? ? ? ? target: `https://${target}.fangxiaobao.net`,

? ? ? ? ? changeOrigin: true,

? ? ? ? },

? ? ? }

? ? }

? })

}

注意

配置完成后,彈框組件的遮罩層可能會(huì)消失;因?yàn)閑l-overlay類名的樣式內(nèi)容被格式化了,所以只需要重寫就行

.el-overlay {? position: fixed;? top: 0;? right: 0;? bottom: 0;? left: 0;? z-index: 2000;? height: 100%;? background-color: var(--el-overlay-color-lighter);? overflow: auto;}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容