所以我试图实现的是从我的应用程序中的页面中提取一个变量,并能够在其他页面中使用它。此变量是从导航栏操作的,该导航栏可从所需的每个页面访问。"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;这些是我的代码的汇总版本,其中包括我遇到问题的部分。如有任何帮助,我们不胜感激!提前感谢!
发布于 2019-07-20 12:22:54
像这样使用命名导出。
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;https://stackoverflow.com/questions/57121773
复制相似问题