You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
429 B
JavaScript

export const getImageUrl = (path) => {
// 如果是绝对URL直接返回
if (path.startsWith('http://') || path.startsWith('https://')) {
return path
}
// 否则处理为本地资源
try {
// return new URL(`/src/assets/${path}`, import.meta.url).href
return `/src/assets/${path}`
} catch (error) {
console.error('图片加载失败:', error)
return ''
}
}