背景
在使用 ant-design-vue 时,一开始按需导入,然后想切换为全局引入时,出现了Antd is not defined错误。
解决方案一
babel-plugin-import 与全局引入的冲突,移除插件
babel.congig.js文件中删除
['import', { libraryName: 'ant-design-vue', libraryDirectory: 'es', style: 'css' }],
[
'@babel/plugin-transform-runtime',
{
corejs: 3
}
],
[
'@babel/plugin-proposal-decorators',
{
legacy: true
}
],
['import', { libraryName: 'ant-design-vue', libraryDirectory: 'es', style: 'css' }], // `style: true` 会加载 less 文件
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread'
]
解决方案二
修改 全局引入 配置
import Antd from 'ant-design-vue/es' //全局引入
非原创