我正在映射一個名為 tours 的數組 export const tourData = [ { id: 1, city: "new york", img: "./img/newyork.jpeg", name: "new york bridge tour", info: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel,repellendus!" },如下所示 state={ tours: tourData} render(){ const {tours} = this.state; return( <section className="tourlist"> {tours.map(tour => { return ( <Tour key={tour.id} tour={tour} removeTour={this.removeTour}/> ) })} </section> )}我將游覽作為道具傳遞到 Tour 組件中。const {id , city , img, name, info} = this.props.tour; const {removeTour} = this.props;webapp 運行良好,但是當我對 Tour 組件進行測試并將值作為 props 傳遞時 const props ={ id : 1, city: 'Test City ', img: 'Test img', name: 'Test name', info: 'Test Info' }我得到了這樣的錯誤無法讀取未定義的屬性“id”但 webapp 工作正常。需要一些幫助,提前致謝
映射數組返回未定義的值
夢里花落0921
2021-10-21 13:36:16