如何在 ReactJS 中包含自定義 JavaScript 并在其中使用對象數組?我正在嘗試顯示歌曲列表。因此,我創建了一個名為SongList.js 的文件,在其中創建了一個對象數組,如何將其包含在我的list.js文件中并在其中使用它?SongList.js 代碼:-const songList = [{ name: "All We Know", artist: "The Chainsmokers ft. Phoebe Ryan", album: "All We Know", }, { name: "Alone", artist: "Alan Walker", album: "Different World", }, { name: "Be Kind", artist: "Marshmello & Halsey", album: "Be Kind", }, { name: "Beach House", artist: "The Chainsmokers", album: "Sick Boy", },];我正在嘗試這樣做,但它不起作用,請告訴我哪里錯了?list.js代碼import React, { Component } from 'react'import './songList.js'export class list extends Component { render() { return ( <div> {songList[0].name} </div> ) }}export default list
如何在 ReactJS 中包含自定義 JavaScript?
一只名叫tom的貓
2023-07-06 19:45:24