网上方法一大堆,试过之后找出了全部导入的简单方法
包含报错[sass] @use rules must be written before any other rules.
按照官方方法:
/* 只需要重写你需要的即可 */
@forward 'element-plus/theme-chalk/src/common/var.scss' with (
$colors: (
"primary": ("base": rgba(58, 143, 121, 1)),
"success": ("base": #80DB7F),
"warning": ("base": #e6a23c),
"danger": ("base": #E88686),
"error": ("base": #E88686),
"info": ("base": #E7E7E7),
),
);
// 如果只是按需导入,则可以忽略以下内容。
// 如果你想导入所有样式:
@use "element-plus/theme-chalk/src/index.scss" as *; //全部导入打开
在vite.config.ts中的css添加:
css: {
preprocessorOptions: {
scss: {
additionalData: `
@use "@/assets/styles/element/index.scss" as *;
@import '@/assets/styles/index.scss';
`//element的文件要在第一位,不然会报错 [sass] @use rules must be written before any other rules.
},
less: {
javascriptEnabled: true
}
},
},
mian.js里面引入css的要注掉
import ElementPlus from 'element-plus'
// import 'element-plus/dist/index.css'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'//汉化
app.use(ElementPlus)