Javascript TypeError:无法分配给只读属性';出口';对象的'#&书信电报;对象>';在ReactJS中
因此,我试图实现的是从我的应用程序的页面中获取一个变量,并能够在其他页面中使用它。该变量通过导航栏进行操作,导航栏可从所需的每个页面访问该变量。“App.js”基本上只是一个导航栏,其他页面显示在它下面。其他页面需要从导航栏中选择/分配值,以便从数据库中提取信息 App.jsJavascript TypeError:无法分配给只读属性';出口';对象的'#&书信电报;对象>';在ReactJS中,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,因此,我试图实现的是从我的应用程序的页面中获取一个变量,并能够在其他页面中使用它。该变量通过导航栏进行操作,导航栏可从所需的每个页面访问该变量。“App.js”基本上只是一个导航栏,其他页面显示在它下面。其他页面需要从导航栏中选择/分配值,以便从数据库中提取信息 App.js let year; let term; class App extends Component { render() { // Here I do things and assign the variabl
let year;
let term;
class App extends Component {
render() {
// Here I do things and assign the variables on top values
}
export default App;
module.exports = year;
module.exports = term;
let year;
let term;
class App extends Component {
render() {
// Here I do things and assign the variables on top values
}
export default App;
export { year, term };
然后,在我的一页上
var year = require("./AdminApp");
var term = require("./AdminApp");
class ViewStudents extends Component {
constructor(props) {
super(props);
this.state = {
year: year,
term: term
}
}
render() {
// Do more magic
}
export default ViewStudents;
这些是我的代码的总结版本,包括我遇到问题的部分。感谢您的帮助!提前谢谢 像这样使用命名导出 App.js
let year;
let term;
class App extends Component {
render() {
// Here I do things and assign the variables on top values
}
export default App;
module.exports = year;
module.exports = term;
let year;
let term;
class App extends Component {
render() {
// Here I do things and assign the variables on top values
}
export default App;
export { year, term };
在您的页面中:
import { year, term } from "./AdminApp";
class ViewStudents extends Component {
constructor(props) {
super(props);
this.state = {
year: year,
term: term
}
}
render() {
// Do more magic
}
export default ViewStudents;
像这样使用命名导出 App.js
let year;
let term;
class App extends Component {
render() {
// Here I do things and assign the variables on top values
}
export default App;
module.exports = year;
module.exports = term;
let year;
let term;
class App extends Component {
render() {
// Here I do things and assign the variables on top values
}
export default App;
export { year, term };
在您的页面中:
import { year, term } from "./AdminApp";
class ViewStudents extends Component {
constructor(props) {
super(props);
this.state = {
year: year,
term: term
}
}
render() {
// Do more magic
}
export default ViewStudents;