在utils文件夹下创建一个getImgUrl.ts文件
- /** vite的特殊性, 需要处理图片 */
- export const require = (imgPath: string) => {
- try {
- const handlePath = imgPath.replace('@', '..')
- console.log('handlePath::', imgPath)
- return new URL(handlePath, import.meta.url).href
- } catch (error) {
- console.warn(error)
- }
- }
-
在需要的页面引入并使用
