成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

React Starter Kit 學(xué)習(xí)筆記

longshengwang / 2017人閱讀

摘要:根據(jù)頁(yè)面中中的例子匯總修改而成。代碼代碼流逝時(shí)間計(jì)時(shí)器按鈕點(diǎn)擊計(jì)數(shù)流逝時(shí)間計(jì)時(shí)器寫(xiě)法實(shí)時(shí)求解一元二次方程調(diào)用組件制作動(dòng)畫(huà)效果代碼僅在例中使用

根據(jù)http://reactjs.cn/react/docs/...頁(yè)面中Starter Kit 15.3.1中的例子匯總修改而成。

HTML代碼





    
    React test
    
    
    
    



    

JS代碼

const container1 = document.getElementById("container1")
const container2 = document.getElementById("container2")
const container3 = document.getElementById("container3")
const container4 = document.getElementById("container4")
const container5 = document.getElementById("container5")
const container6 = document.getElementById("container6")


//1 "Hello" + name
function Welcome(props) {
    return 

Hello, { props.name } < /h1>; } const element = < Welcome name = "Diary" / > ; ReactDOM.render( element, container1 ); //2 流逝時(shí)間計(jì)時(shí)器 var Elapsed = React.createClass({ render: function () { var elapsed = Math.round(this.props.elapsed / 100); var seconds = elapsed / 10 + (elapsed % 10 ? "" : ".0"); var message = "React has been successfully running for " + seconds + " seconds."; return

{ message } < /p>; } }); var start = new Date().getTime(); setInterval(function () { ReactDOM.render( < Elapsed elapsed = { new Date().getTime() - start } / > , container2 ); }, 50); //3 按鈕點(diǎn)擊計(jì)數(shù) var Counter = React.createClass({ getInitialState: function () { return { count: 2, sum: 100 }; }, handleClick: function () { this.setState({ count: this.state.count * this.state.count, }); }, handleDoubleClick: function () { this.setState({ count: 2, sum: 1000 }) }, render: function () { return ( < button onClick = { this.handleClick } onDoubleClick = { this.handleDoubleClick }> sum - count: { this.state.sum - this.state.count } < /button> ); } }); ReactDOM.render( < Counter / > , container3 ); //4 流逝時(shí)間計(jì)時(shí)器(ES6寫(xiě)法) class ExampleApplication extends React.Component { render() { var elapsed = Math.round(this.props.elapsed / 100); var seconds = elapsed / 10 + (elapsed % 10 ? "" : ".0"); var message = `React has been successfully running for ${seconds} seconds.`; return

{ message } < /p>; } } var start = new Date().getTime(); setInterval(() => { ReactDOM.render( < ExampleApplication elapsed = { new Date().getTime() - start }/>, container4 ); }, 50); //5 實(shí)時(shí)求解一元二次方程 var QuadraticCalculator = React.createClass({ getInitialState: function() { return { a: 1, b: 3, c: -4 }; }, /** * This function will be re-bound in render multiple times. Each .bind() will * create a new function that calls this with the appropriate key as well as * the event. The key is the key in the state object that the value should be * mapped from. */ handleInputChange: function(key, event) { var partialState = {}; partialState[key] = parseFloat(event.target.value); this.setState(partialState); }, render: function() { var a = this.state.a; var b = this.state.b; var c = this.state.c; var root = Math.sqrt(Math.pow(b, 2) - 4 * a * c); var denominator = 2 * a; var x1 = (-b + root) / denominator; var x2 = (-b - root) / denominator; return (

ax2 + bx + c = 0

Solve for x:




x: {x1}, {x2}

); } }); ReactDOM.render( , container5 ); //6 調(diào)用React組件CSSTransitionGroup制作動(dòng)畫(huà)效果 var CSSTransitionGroup = React.addons.CSSTransitionGroup; var INTERVAL = 2000; var AnimateDemo = React.createClass({ getInitialState: function() { return {current: 0}; }, componentDidMount: function() { this.interval = setInterval(this.tick, INTERVAL); }, componentWillUnmount: function() { clearInterval(this.interval); }, tick: function() { this.setState({current: this.state.current + 1}); }, render: function() { var children = []; var colors = ["#fac", "#cdc", "#36d", "#ca0", "#0aa"]; for (var i = this.state.current, pos=0; i < this.state.current + colors.length; i++, pos++) { var style = { left: pos * 128, background: colors[i % colors.length] }; children.push(
{i}
); } return ( {children} ); } }); ReactDOM.render( , container6 );

CSS代碼(僅在例6中使用)

.example-enter,
.example-leave {
  -webkit-transition: all .25s;
  transition: all .25s;
}

.example-enter,
.example-leave.example-leave-active {
  opacity: 0.01;
}

.example-leave.example-leave-active {
  margin-left: -128px;
}

.example-enter {
  margin-left: 128px;
}

.example-enter.example-enter-active,
.example-leave {
  margin-left: 0;
  opacity: 1;
}

.animateExample {
  display: block;
  height: 128px;
  position: relative;
  width: 384px;
}

.animateItem {
  color: white;
  font-size: 36px;
  font-weight: bold;
  height: 128px;
  line-height: 128px;
  position: absolute;
  text-align: center;
  -webkit-transition: all .25s; /* TODO: make this a move animation */
  transition: all .25s; /* TODO: make this a move animation */
  width: 128px;
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/81877.html

相關(guān)文章

  • 服務(wù)端渲染的React手腳架。完美使用 React, Redux, and React-Router

    摘要:服務(wù)端渲染的手腳架這個(gè)啟動(dòng)包的設(shè)計(jì)是為了讓你使用一整套最新最酷的前端技術(shù),所有都是可配置,富特性,基于已經(jīng)提供代碼熱加載,使用預(yù)處理,單元測(cè)試,代碼覆蓋率報(bào)告,代碼分割等等更多。 Universal React Starter Kit 服務(wù)端渲染的React手腳架 這個(gè)啟動(dòng)包的設(shè)計(jì)是為了讓你使用一整套最新最酷的前端技術(shù),所有都是可配置,富特性,基于webpack已經(jīng)提供代碼熱加載,使用...

    zhouzhou 評(píng)論0 收藏0
  • 服務(wù)端渲染的React手腳架。完美使用 React, Redux, and React-Router

    摘要:服務(wù)端渲染的手腳架這個(gè)啟動(dòng)包的設(shè)計(jì)是為了讓你使用一整套最新最酷的前端技術(shù),所有都是可配置,富特性,基于已經(jīng)提供代碼熱加載,使用預(yù)處理,單元測(cè)試,代碼覆蓋率報(bào)告,代碼分割等等更多。 Universal React Starter Kit 服務(wù)端渲染的React手腳架 這個(gè)啟動(dòng)包的設(shè)計(jì)是為了讓你使用一整套最新最酷的前端技術(shù),所有都是可配置,富特性,基于webpack已經(jīng)提供代碼熱加載,使用...

    RayKr 評(píng)論0 收藏0
  • 服務(wù)端渲染的React手腳架。完美使用 React, Redux, and React-Router

    摘要:服務(wù)端渲染的手腳架這個(gè)啟動(dòng)包的設(shè)計(jì)是為了讓你使用一整套最新最酷的前端技術(shù),所有都是可配置,富特性,基于已經(jīng)提供代碼熱加載,使用預(yù)處理,單元測(cè)試,代碼覆蓋率報(bào)告,代碼分割等等更多。 Universal React Starter Kit 服務(wù)端渲染的React手腳架 這個(gè)啟動(dòng)包的設(shè)計(jì)是為了讓你使用一整套最新最酷的前端技術(shù),所有都是可配置,富特性,基于webpack已經(jīng)提供代碼熱加載,使用...

    DC_er 評(píng)論0 收藏0
  • 前端相關(guān)框架總和

    摘要:前端框架總和有很多小伙伴工作開(kāi)發(fā)需要很多的框架和軟件,那么接下來(lái)就為大家介紹一下相關(guān)的框架和軟件設(shè)計(jì)用于構(gòu)建用戶界面的聲明性,高效且靈活的庫(kù)。為應(yīng)用程序中的每個(gè)狀態(tài)設(shè)計(jì)簡(jiǎn)單視圖,當(dāng)數(shù)據(jù)發(fā)生變化時(shí),將有效地更新和呈現(xiàn)正確的組件。 前端框架總和 有很多小伙伴工作開(kāi)發(fā)需要很多的框架和軟件,那么接下來(lái)就為大家介紹一下相關(guān)的框架和軟件 1.UI設(shè)計(jì) react ?? 用于構(gòu)建用戶界面的聲明性...

    senntyou 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<