【发布时间】:2019-04-16 13:11:30
【问题描述】:
所以我正在创建一个简单的反应应用程序,它导出一个文件,其中包含一个返回对象数组的函数:
export const listStudents = () => {
return [{name:"Ljuben", lastName:"Angelkoski", indeks:"161161", nasoka:"KNI"},
{name:"Pere", lastName:"Anastasov", indeks:"17350", nasoka:"PET"},
{name:"Filip", lastName:"Shabanoski", indeks:"173521", nasoka:"PET"},
{name:"Martin", lastName:"Krsteski", indeks:"163544", nasoka:"KNI"},
{name:"Nikola", lastName:"Nacevski", indeks:"154874", nasoka:"ASI"}]; // replace the empty array with actual array with at least 5 student objects
}
在我的主要组件中,我有以下代码:
import React, {Component} from 'react'
import listStudents from './repository/studentRepository.js'
class Main extends Component{
constructor(props){
super(props);
this.state={
students: listStudents
}
}
render(){
return (
<h2></h2>
)
}
}
export default Main
但是,当我运行该应用程序时,它给了我这个错误:
./src/Main.js
Attempted import error: './repository/studentRepository.js' does not contain a default export (imported as 'listStudents').
有什么想法吗?
【问题讨论】:
-
编辑:你需要正确
import你的studentRepository.js -
还将 this.state={ students: listStudents } 更改为 this.state={ students: listStudents() }
-
任何答案对您有用吗?如果是这种情况,请考虑 accepting one of them。
标签: reactjs