2 回答

TA贡献1805条经验 获得超10个赞
获取网址
fetch (`https://randomuser.me/api/?seed=${seed}`). then (d=>d.json()).then(e=>console.log(e))
其中种子是一个像这样的字符串
const seed ="fea8be3e64777240"

TA贡献1900条经验 获得超5个赞
如果您有兴趣生成带有详细信息的随机用户,可以使用另一个免费 API。
API:https ://wirespec.dev/Wirespec/projects/apis/Stackoverflow/apis/getUserDetails
端点:https://api.wirespec.dev/wirespec/stackoverflow/getuserdetails? id=100
Wirespec 允许您创建最多 100 万个随机用户(包括头像)。检查一下:

TA贡献1886条经验 获得超2个赞
你需要使用状态来获取结果
import React, {useState, useEffect} from 'react'
import { useParams } from 'react-router-dom';
export const UserDetail = () => {
const {userid} = useParams()
const [result, setResult] = useState([]);
useEffect(() => {
fetch(`/user-detail/${userid}`).then(res=>res.json()).then(result=> {
console.log(result)
setResult(result);
})
}, [])
return (
<div>
</div>
)
}
添加回答
举报