我是反應 js 的新手,我收到 Uncaught TypeError: Cannot read properties of undefined (reading 'url') 錯誤由于獲取影像映射。如果我使用檔案上已有的資料,它作業正常,但如果我必須獲取資料,它會創建這個錯誤。這是嘗試過的。請讓我知道如何解決此錯誤。
const THECATAPI = 'https://api.thecatapi.com/v1/breeds'
const [catList, setCatList] = useState([])
const axiosPosts = async () => {
try {
const response = await axios(THECATAPI)
setCatList(response.data)
} catch (error) {
console.log('erroRRRR');
}
};
// return
<div>
{
catList.map((obj, i) => (
<div >
<img src={obj['image']['url']} alt='loading' />
</div>
}
</div>
uj5u.com熱心網友回復:
由于您正在訪問陣列中的嵌套值,因此在某些情況下,可能不會顯示該值。您可以在訪問嵌套欄位時使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/469208.html
標籤:javascript 反应 axios
上一篇:使用滾動只執行一次事件偵聽器
