feat: optimize achievements tab loading

This commit is contained in:
Tim
2025-08-09 16:53:27 +08:00
parent 6b5b6b8c81
commit 760bc4fc4b
2 changed files with 31 additions and 31 deletions

View File

@@ -1,7 +1,7 @@
<template>
<div class="achievements-list">
<div
v-for="medal in medals"
v-for="medal in props.medals"
:key="medal.type"
class="achievements-list-item"
>
@@ -25,37 +25,13 @@
</template>
<script setup>
import { ref, watch } from 'vue'
import { API_BASE_URL, toast } from '../main'
const props = defineProps({
userId: {
type: Number,
required: true
defineProps({
medals: {
type: Array,
required: true,
default: () => []
}
})
const medals = ref([])
const fetchMedals = async () => {
const res = await fetch(`${API_BASE_URL}/api/medals?userId=${props.userId}`)
if (res.ok) {
medals.value = await res.json()
} else {
medals.value = []
toast.error('获取成就失败')
}
}
watch(
() => props.userId,
id => {
if (id) {
fetchMedals()
}
},
{ immediate: true }
)
</script>
<style scoped>