Upgrade to Pro — share decks privately, control downloads, hide ads and more …

react 简介

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Yuheng Zhang Yuheng Zhang
November 14, 2014
370

react 简介

react 简介

Avatar for Yuheng Zhang

Yuheng Zhang

November 14, 2014
Tweet

Transcript

  1. Features • ⻚页⾯面渲染性能好,使⽤用 virtual DOM,避免操纵 DOM 损耗性能 • DOM 的读/写批量进⾏行,减少

    layout 计算次数 • 当属性变化时,基于 virtual DOM 全部重新渲染 • 不需要借⽤用模版语⾔言实现逻辑,no strings • 不需要专⻔门操作 DOM 的库(jQuery)
  2. var ExampleApplication = React.createClass({ render: function() { var appName =

    this.props.appName; var message = 'React has been successfully running.' + ' Appname is: ' + appName; return React.DOM.p(null, message); } }); var ExampleApplicationFactory = React.createFactory(ExampleApplication); React.render( ExampleApplicationFactory({appName: 'Demo'}), document.getElementById('container') ); Basic usage
  3. Full example <!DOCTYPE html> <html> <head> <meta http-equiv='Content-type' content='text/html; charset=utf-8'>

    <title>Example</title> <link rel="stylesheet" href="../shared/css/base.css" /> </head> <body> <h1>Example</h1> <div id="container"> </div> <script src="../../build/react.js"></script> <script> var ExampleApplication = React.createClass({ render: function() { var appName = this.props.appName; var message = 'React has been successfully running.' + ' Appname is: ' + appName; return React.DOM.p(null, message); } }); var ExampleApplicationFactory = React.createFactory(ExampleApplication); React.render( ExampleApplicationFactory({appName: 'Demo'}), document.getElementById('container') ); </script> </body> </html>
  4. View • 从 store 获取数据,并监听 store 的变化 • 数据由 store

    传⼊入 view • 当 view 通过 setState 改变 state 时,重 新渲染 • 当有浏览器事件时,调⽤用 action 对应⽅方法
  5. Q&A