美文网首页
React-Native的绑定this

React-Native的绑定this

作者: CowboyBebop | 来源:发表于2016-12-08 14:11 被阅读64次
    • 1,绑定this,不传参
    export default class Nearby extends Component{    
        static defaultProps={        
              name:'111'   
         }        
        render(){        
              return(            
                    <View style={styles.containerStyle}>                
                          <Text style={styles.textStyle} onPress={this.Click}>Home</Text>            
                    </View>        
            );   
         }    
         Click = () =>{        
                console.log(this.props.name)    
        }
    }
    
    • 2,绑定this,传参
    export default class Nearby extends Component{    
        static defaultProps={        
            name:'111'   
         }    
        render(){        
          return(            
            <View style={styles.containerStyle}>                
                <Text style={styles.textStyle} onPress={()=>this.Click('222')}>Home</Text>            
          </View>       
         );    
        }    
        Click = (name) =>{        
            console.log(this.props.name)   
         }
      }
    

    相关文章

      网友评论

          本文标题:React-Native的绑定this

          本文链接:https://www.haomeiwen.com/subject/zahsmttx.html