自定义工具类没有样式问题
在使用按需引入的前提下,如果自定义了一个消息工具类,此时不会加载样式:
import {ElMessage} from 'element-plus'
/**
* 消息
* {
* text: 消息文字
* code: 200-成功、0-警告、其他都失败
* }
*/
function msg(obj) {
let type = 'error'
if (obj.code === 200) {
type = 'success'
} else if (obj.code === 0) {
type = 'warning'
}
ElMessage({
message: obj.text,
type: type,
})
}
export default {msg}
解决办法
那么使用后发现没有样式,可以在main.js
中直接将样式文件引入
// 解决因按需引入造成的工具类没有样式问题
import 'element-plus/theme-chalk/index.css'