
前言
在刚开始使用vue3+vite+ts项目中安装element-plus,使用组件不起作用,报错如下:
UnCaugh SyntaxError:The requested module '/node_modules/element-plus/lib/locale/lang/zh-cn.js?v=7.0.2' does not provide an export named 'default'
解决方案
删除
node_modules文件夹和package-lock.json文件修改
package.json修改
Vue版本号,必须3.3.2以上安装
element-plus,重新npm install i --force,强制安装,否则会报错
element-plus找不到样式
在main.js中,找到引入element-plus样式
解决也很简单,既然自己已经安装了element-plus依赖,却找不到文件,大概率是路径变了。于是手动翻了下node-modules,发现果然整个theme-chalk文件夹都被挪了位置
旧版本安装位置
import 'element-plus/lib/theme-chalk/index.css'; // 这里巨坑,路径问题
新版本安装位置
import 'element-plus/dist/index.css';
如果发现样式问题,那大概率是引入样式的位置问题
总结
element-plus使用与ElementUI没啥多大区别,但是是有些坑的,需要踩

(能绘画,能问答)

在Vue3项目中使用Vite安装Element-Plus时遇到组件无法正常工作和样式丢失的问题。解决方案包括删除node_modules、修改package.json中的版本号、重新安装,并检查样式引入路径,因为新版本的安装位置可能发生了变化。
3994

被折叠的 条评论
为什么被折叠?



