Access: https: //www.cnblogs.com/chenxi188/p/11702799.html
Spend my-app-built section of the project:
my-app/ README.md node_modules/ package.json .gitignore public/ favicon.ico index.html manifest.json src/ App.css App.js App.test.js index.css index.js logo.svg
A binding state data state
1. Create a new componets in the src directory, to put its own components built:
In the components folder, a new component: home.js enter the following
React Import, {from} the Component 'REACT' ; class Homes the extends the Component { // the next two Stationary written constructor () { Super (); // the following acts to establish a status component data the this .STATE = { name: " alice " , Age: 20 is , Sex: " female " , UserInfo: {username: 'Sky' } } } the render () { // following this.state.xxx bind to the status data to a front end return ( <div> <h2> this is Home.js assembly </ H2> <P>My name is: { the this} .state.name </ the p-> <the p-> my age is: { the this .state.age} </ the p-> <the p-> My gender is: { the this .state.sex} </ the p-> <the p-> I username: { the this .state.userinfo.username} </ P> </ div> ); } }; Export default Homes;
2. Then APP.js root into the following components:
React Import, {from} the Component 'REACT' ; Import logo from './logo.svg' ; Import './App.css' ; // introduced from the components folder written Home.js assembly import Homes from' ./components/Home ' ; class the app the extends the component { // following <Homes /> is written when the home assembly invoked to the render () { return ( <className = div "the app"> <h1 of> here app .js root element </ h1 of> <Homes /> </ div> );} } Export default the App;
3. Run: Back to my-app items in cmd run code, project start to see results
Elevation start
running result: