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

資訊專欄INFORMATION COLUMN

React學(xué)習(xí)筆記—屬性轉(zhuǎn)移

fanux / 1290人閱讀

摘要:我們可以使用屬性延伸覆蓋原來的屬性值手動轉(zhuǎn)移大部分情況你應(yīng)該明確的向下傳遞屬性,這樣可以確保你只需要暴露內(nèi)部的一個子集。但是屬性屬性或者屬性呢利用轉(zhuǎn)移使用了的結(jié)構(gòu)化賦值,所以引入時要加入,如下

React當(dāng)中的組件嵌套很常見,外部組件暴露的屬性也許會干一些復(fù)雜的實(shí)現(xiàn)細(xì)節(jié)。
我們可以使用屬性延伸覆蓋原來的屬性值

var Component = React.createClass({
    render: function () {
        return 
this is a div
} }); React.render( , document.body );
手動轉(zhuǎn)移

大部分情況你應(yīng)該明確的向下傳遞屬性,這樣可以確保你只需要暴露內(nèi)部API的一個子集。

var FancyCheckbox = React.createClass({
  render: function() {
    var fancyClass = this.props.checked ? "FancyChecked" : "FancyUnchecked";
    return (
      
{this.props.children}
); } }); React.render( Hello world! , document.getElementById("example") );

但是name屬性、title屬性或者onMouseOver屬性呢?

利用JSX ... 轉(zhuǎn)移
var FancyCheckbox = React.createClass({
    render: function() {
        var { checked, ...other } = this.props;
        var fancyClass = checked ? "FancyChecked" : "FancyUnchecked";
        // `other` contains { onClick: console.log } but not the checked property
        return (
            
); } }); React.render( Hello world! , document.body );
  

var { checked, ...other } = this.props;使用了ES7的結(jié)構(gòu)化賦值,所以引入時要加入harmony,如下:

                
閱讀需要支付1元查看
<