第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

在反應(yīng)中顯示對象數(shù)組

在反應(yīng)中顯示對象數(shù)組

喵喵時光機(jī) 2023-06-09 15:20:21
**React 和 Node 的新手,正在嘗試按照一些教程將數(shù)據(jù)提取到功能組件中。我設(shè)法創(chuàng)建了服務(wù)器并建立了數(shù)據(jù)庫連接并按照 tuts 獲取數(shù)據(jù)以做出反應(yīng),但是當(dāng)我繼續(xù)通過輸出數(shù)據(jù)來使用數(shù)據(jù)時,我沒有得到任何結(jié)果。我附上了控制臺的截圖,它顯示我的狀態(tài),練習(xí),有數(shù)據(jù)。任何人都可以通過指導(dǎo)我錯在哪里來幫助我。也許它是一個對象數(shù)組,我需要將它轉(zhuǎn)換成其他東西?**import React,{useState,useEffect} from 'react';import axios from 'axios';const Navbar = () => {const [exercises, setCount] = useState([]);useEffect(() => {    axios        .get('http://localhost:5000/exercises/')        .then(response => {            setCount([...exercises, response.data]);                     })}, []);console.log({exercises});var formatted = exercises.map((item) => {return( <div key="1">   <p>{item.username}</p>   <p>{item.duratiom}</p>   </div>)}); return( <div> {formatted} </div>) ;}export default Navbar;[![enter image description here][1]][1]從服務(wù)器獲取調(diào)用router.route('/').get((req,res) => {Exercise.find()    .then(exercises => res.json(exercises))    .catch(err => res.status(400).json('Error:'+err));});
查看完整描述

1 回答

?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個贊

在您的州添加數(shù)據(jù)時添加傳播運(yùn)算符:

 setCount([...exercises, ...response.data]);


查看完整回答
反對 回復(fù) 2023-06-09
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號