1、不能使用require引入图片
vite版本
"vite": "^5.2.0"
解决:在utils文件下新建getImgUrl.js
export const require = (imgPath) => {
try {
const handlePath = imgPath.replace('@', '..')
return new URL(handlePath, import.meta.url).href
} catch (error) {
console.warn(error)
}
}
组件中使用
import { require } from '@/utils/getImgUrl'
<img :src="require('@/assets/' + imgUrl)" alt="">
2、引入element-plus中文包错误
//改之前:
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
//改之后
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
<script setup>
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
let locale = zhCn;
</script>
<template>
<el-config-provider :locale="locale">
<router-view />
</el-config-provider>
</template>