ReactJS 2017-04-12


What you need is a way to import only a specific part of a file into another file.

The answer is something called module.exports.module.exports comes from Node.js's module system, just like require does.

NOTE:Any component rendered by a different component must be included in module.exports.

Remember that every file is invisible to every other file, except for what you choose to expose via module.exports.

var React = require('react');
var NavBar = React.createClass({
  render: function () {
    var pages = ['home', 'blog', 'pics', 'bio', 'art', 'shop', 'about', 'contact'];
    var navLinks ={
      return (
        <a href={'/' + page}>
    return <nav>{navLinks}</nav>;

Now, when ProfilePage.js uses requireto import NavBar.js, it will get back exactly what it wants: the NavBar component class.

var React = require('react');
var ReactDOM = require('react-dom');
var NavBar = require('./NavBar');
var ProfilePage = React.createClass({
  render: function () {
    return (
<NavBar />
        <h1>All About Me!</h1>
        <p>I like movies and blah blah blah blah blah</p>
        <img src="" />

本文由 方方無 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。



shijiebei 365bet manbetx 188bet xinshui caipiao 95zz tongbaoyule beplay 88bifa 18luck betway bwin hg0088 aomenjinshayulecheng ca88 shenbotaiyangcheng vwin w88 weide