零基礎學了快兩個月的React了(React-native + React.js),所謂的000基礎是指徹底不懂JS,CSS,HTML5還有任何相關概念Dom,Server rendering等等。
PS:這裏說服務器渲染,是誤打誤撞了,我剛只是想把Jade Template換掉而已。css
原本我一個移動端的,和React.js是不沾邊的,可是我學的時候React-native(0.25)教程裏有句「咱們認爲你有Reactjs的相關經驗,若是沒有,能夠學一下」,原文以下:html
"We assume you have experience writing applications with React. If not, you can learn about it on the React website."react
技多不加深嘛,既然大神都說了,正好有阿里雲能夠練手, 開搞!!!jquery
Express框架,使用的默認模版引擎Jade(新版更名爲Pug)。由express-jsx負責將.jsx翻譯成對應的.js文件,以便能在jade引用webpack
./views/<layout.jade>git
doctype html html head title=title link(rel='stylesheet', href='/css/style.css') link(rel='stylesheet', href='/css/bootstrap.min.css') block head body script(src='/js/react.min.js') script(src='/js/react-dom.min.js') block content script(src='/js/jquery.min.js') script(src='/js/bootstrap.min.js')
./views/<index.jade>es6
extends layout block content <div id='content'></div> script(src='index.js') script. 'use strict'; var result = !{param}; ReactDOM.render(React.createElement(Index, { name: result }), content);
./views/<index.jsx>github
var Index = React.createClass({ getInitialState: function () { return { count: 0 }; }, handleClick: function () { this.setState({ count: this.state.count + 1, }); }, render: function () { return ( <button onClick={this.handleClick}> Click {this.props.name.name}! Number of clicks: {this.state.count} </button> ); } });
./routes/index.jsweb
var express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { var jsonStr = JSON.stringify({'name': 'here'}, {indent: true}); res.render('index', { param: jsonStr }); }); module.exports = router;
Express框架,使用模版引擎express-react-views。由webpack負責將.jsx翻譯成對應的.js文件(webpack順帶解決了es6語法問題)。express
寫不動了,感興趣直接看代碼吧: