![](/img/trans.png)
[英]Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
[英]TypeError: Cannot assign to read only property 'exports' of object '#<Object>' in ReactJS
所以我想要實現的是從我的應用程序頁面中獲取一個變量,並能夠在其他頁面中使用它。 該變量是從導航欄上操作的,該導航欄可以從所需的每個頁面進行訪問。 “ App.js”基本上只是一個導航欄,其他頁面顯示在其下方。 其他頁面需要從導航欄中選擇/分配值,以便從數據庫中提取信息。
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;
然后,在我的其中一頁上
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;
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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.