亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從randomuser API獲取用戶的用戶詳細信息?

如何從randomuser API獲取用戶的用戶詳細信息?

尚方寶劍之說 2024-01-18 20:43:12
在 React 作業中,我嘗試從 randomuser.me API 獲取用戶詳細信息并將其顯示在另一個組件上。除了無法從其 id 獲取用戶詳細信息之外,一切都已完成管理面板.js<TableBody>          {results.map((person) => (            <TableRow key={person.id.value}>                <TableCell component="th" scope="row">{person.name.first}</TableCell>                <TableCell align="right">{person.name.last}</TableCell>                <TableCell align="center">{person.location.street.name + ',' + person.location.street.number + ',' + person.location.state + ',' + person.location.country  }</TableCell>                <TableCell align="right"><img src={person.picture.thumbnail} /></TableCell>                <TableCell align="center">{person.email}</TableCell>                <TableCell align="right">{person.dob.date}</TableCell>                <TableCell align="right">                <Button variant="contained" color="primary" >                    <Link style={{color:'white'}} to={`/user-detail/${person.login.uuid}`}>View Details</Link>                </Button>                </TableCell>            </TableRow>          ))}</TableBody>單擊鏈接后,它會重定向到另一個頁面,如下所示用戶詳細信息import React, {useEffect} from 'react'import { useParams } from 'react-router-dom';export const UserDetail = () => {    const {userid} = useParams()    useEffect(() => {        fetch(`/user-detail/${userid}`).then(res=>res.json()).then(result=> {            console.log(result)        })    }, [])    return (        <div>                    </div>    )}Bu,當控制臺日志顯示此錯誤“未捕獲(承諾中)SyntaxError:位置 0 處的 JSON 中出現意外標記 <”時我犯了什么錯誤?
查看完整描述

2 回答

?
holdtom

TA貢獻1805條經驗 獲得超10個贊

獲取網址

fetch (`https://randomuser.me/api/?seed=${seed}`). then (d=>d.json()).then(e=>console.log(e))

其中種子是一個像這樣的字符串

const seed ="fea8be3e64777240"


查看完整回答
反對 回復 2024-01-18
?
梵蒂岡之花

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 萬個隨機用戶(包括頭像)。檢查一下:

https://wirespec.dev


查看完整回答
反對 回復 2024-01-18
?
MM們

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>

    )

}


查看完整回答
反對 回復 2024-01-18
  • 2 回答
  • 0 關注
  • 270 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號