feat: fix avatar problem

This commit is contained in:
tim
2025-07-07 01:46:11 +08:00
parent fe4ccf9efc
commit 87b2e9b19e
3 changed files with 12 additions and 11 deletions

View File

@@ -104,15 +104,15 @@ const CommentItem = {
const replyList = props.comment.reply || (props.comment.reply = []) const replyList = props.comment.reply || (props.comment.reply = [])
replyList.push({ replyList.push({
id: data.id, id: data.id,
userName: data.author, userName: data.author.username,
time: new Date(data.createdAt).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' }), time: new Date(data.createdAt).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' }),
avatar: 'https://picsum.photos/200/200', avatar: data.avatar.username,
text: data.content, text: data.content,
reply: (data.replies || []).map(r => ({ reply: (data.replies || []).map(r => ({
id: r.id, id: r.id,
userName: r.author, userName: r.author.username,
time: new Date(r.createdAt).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' }), time: new Date(r.createdAt).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' }),
avatar: 'https://picsum.photos/200/200', avatar: r.avatar,
text: r.content, text: r.content,
reply: [] reply: []
})) }))

View File

@@ -46,7 +46,7 @@ export default {
data() { data() {
return { return {
dropdownVisible: false, dropdownVisible: false,
avatar: 'https://picsum.photos/40' avatar: ''
} }
}, },
computed: { computed: {
@@ -61,9 +61,7 @@ export default {
if (user && user.avatar) { if (user && user.avatar) {
this.avatar = user.avatar this.avatar = user.avatar
} }
} else { }
this.avatar = 'https://picsum.photos/40'
}
} }
await updateAvatar() await updateAvatar()

View File

@@ -24,7 +24,7 @@
<div class="info-content-container" ref="postItems"> <div class="info-content-container" ref="postItems">
<div class="user-avatar-container"> <div class="user-avatar-container">
<div class="user-avatar-item"> <div class="user-avatar-item">
<img class="user-avatar-item-img" src="https://picsum.photos/200/200" alt="avatar"> <img class="user-avatar-item-img" :src="author.avatar" alt="avatar">
</div> </div>
</div> </div>
@@ -107,6 +107,7 @@ export default {
const postId = route.params.id const postId = route.params.id
const title = ref('') const title = ref('')
const author = ref('')
const postContent = ref('') const postContent = ref('')
const category = ref('') const category = ref('')
const tags = ref([]) const tags = ref([])
@@ -120,9 +121,9 @@ export default {
const mapComment = c => ({ const mapComment = c => ({
id: c.id, id: c.id,
userName: c.author, userName: c.author.username,
time: new Date(c.createdAt).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' }), time: new Date(c.createdAt).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' }),
avatar: 'https://picsum.photos/200/200', avatar: c.author.avatar,
text: c.content, text: c.content,
reply: (c.replies || []).map(mapComment) reply: (c.replies || []).map(mapComment)
}) })
@@ -135,6 +136,7 @@ export default {
if (!res.ok) return if (!res.ok) return
const data = await res.json() const data = await res.json()
postContent.value = data.content postContent.value = data.content
author.value = data.author
title.value = data.title title.value = data.title
category.value = data.category category.value = data.category
tags.value = data.tags || [] tags.value = data.tags || []
@@ -218,6 +220,7 @@ export default {
return { return {
postContent, postContent,
author,
title, title,
category, category,
tags, tags,