React js ES5 module.exports问题

时间:2017-09-30 06:26:21

标签: reactjs ecmascript-5

文件名= main.jsx

var React = module.exports = require("react");
var ReactDOM = require("react-dom");
var SchoolsList = require("./components/SchoolsList.jsx");
var schoolsStore = require("./stores/schoolsStore");
var _schools = [];
var getSchoolsCallback = function(schools){
    _schools = schools;
    render();
};
schoolsStore.onChange(getSchoolsCallback);

function render(){
    ReactDOM.render(<SchoolsList schools={_schools} />, document.getElementById("container"));    
}

文件名= app.jsx

//var React = require("react");
var SchoolInfo = require("./SchoolInfo.jsx")
var AddSchool = require("./AddSchool.jsx");

module.exports = React.createClass({
   render:function(){
       return(
           <div className="row">
                <div className="col-md-6">
                    <AddSchool />
                </div>
                <div className="col-md-6">
                    {
                        this.props.schools.map(function(s,index){
                            return(
                                <SchoolInfo info={s} key={"school"+index} />
                            )         
                        })
                    }
                </div>
           </div>
       )
   } 
});

我在var React = module.exports = require("react");文件中使用了main.jsx。该模块使用了所有类,因此我使用了导出模块module.exports。但我无法在另一个类中使用React模块。如果可能,如果主文件中的导出模块和我可以在所有类中访问该模块?

0 个答案:

没有答案