错误:
使用element plus 自动导入组件时 eslint 报错
解决方法:
一、 在 .eslintrc.cjs 文件中添加 相关配置
module.exports = {
// ...
globals: {
ElMessage: 'readonly',
ElMessageBox: 'readonly',
ElLoading: 'readonly'
}
}
二、在 src 目录下 新建 Element-puls.d.ts 文件,并配置信息
export {}
declare global {
const ElMessage: (typeof import('element-plus'))['ElMessage']
const ElMessageBox: (typeof import('element-plus'))['ElMessageBox']
const ElLoading: (typeof import('element-plus'))['ElLoading']
}
三、在 tsconfig.app.json / tsconfig.json / tsconfig.node.json 中找到 "include" 属性 添加 Element-puls.d.ts 文件信息
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": [
"env.d.ts",
"src/**/*",
"src/**/*.vue",
"Element-puls.d.ts" // 添加信息
],
"exclude": [
"src/**/__tests__/*"
],
}