fix(图片): 更新默认图片的加载问题和引入方式

This commit is contained in:
hzj 2025-09-22 16:18:19 +08:00
parent 844175ba6c
commit a371df6bba
2 changed files with 7 additions and 5 deletions

View File

@ -97,7 +97,8 @@ const props = defineProps({
const defaultAvatarUrl = (e) => { const defaultAvatarUrl = (e) => {
console.log('头像资源出错') console.log('头像资源出错')
e.target.src = '/src/assets/images/WeeklyStar/defaultAvatar.png' e.target.onerror = null //
e.target.src = new URL('/src/assets/images/WeeklyStar/defaultAvatar.png', import.meta.url).href
} }
</script> </script>

View File

@ -441,7 +441,7 @@
> >
<div style="width: 70%; display: flex; justify-content: space-around; align-items: center"> <div style="width: 70%; display: flex; justify-content: space-around; align-items: center">
<!-- 排名 --> <!-- 排名 -->
<div style="color: #edb247; font-weight: 700">{{ myRanking.rank }}</div> <div style="color: #edb247; font-weight: 700">{{ myRanking.rank || 999 }}</div>
<!-- 头像 --> <!-- 头像 -->
<img <img
:src="myRanking.userAvatar" :src="myRanking.userAvatar"
@ -844,16 +844,17 @@ const showRanking = computed(() => {
// //
const handleImageError = (e, type) => { const handleImageError = (e, type) => {
console.log('图片资源出错') console.log('图片资源出错')
e.target.onerror = null e.target.onerror = null //
if ((type = 'GOLD')) { if ((type = 'GOLD')) {
e.target.src = '/src/assets/icon/coin.png' e.target.src = new URL('/src/assets/icon/coin.png', import.meta.url).href
} }
} }
// //
const defaultAvatarUrl = (e) => { const defaultAvatarUrl = (e) => {
console.log('头像资源出错') console.log('头像资源出错')
e.target.src = '/src/assets/images/WeeklyStar/defaultAvatar.png' e.target.onerror = null //
e.target.src = new URL('/src/assets/images/WeeklyStar/defaultAvatar.png', import.meta.url).href
} }
// //