怎么通过id去请求接口获取对应名称并返回,
需要将id转换为用户名
代码如下,有人帮忙解答一下吗,用的是vue3,最好能给出代码
<template>
<el-card shadow="never" body-style="padding:10px;" v-for="(item, index) in list" :key="index">
<div class="title">{{ item.title }}</div>
<div class="title-info">
<el-text class="mx-1" v-for="cat in catList">
<span v-if="cat.id === item.articleCatId">
{{ cat.catName }}
</span>
</el-text>
<el-text class="mx-1">
<span>
<!-- 将用户id转换为用户名称 -->
{{ item.userinfoId }}
</span>
</el-text>
</div>
</el-card>
</template>
<script setup>
import { getCatNameById } from '@/api/article'
// getUserById为已封装好的axios请求,接收用户id,返回用户信息
import { getUserById } from '@/api/user'
import { ref, computed } from 'vue'
defineProps(['list', 'catList'])
</script>
<style scoped>
.title {
width: 100%;
word-wrap: none;
overflow: hidden;
}
.title-info {
margin-top: 10px;
}
</style>