react native fun() fun=()=>的区别

单独的时候这两个都没有问题,就是如果在react native 中运行的时候,第一个会无法访问this.state.mycount变量,原因是函数需要bind的,如果没有这样,那么需要使用fun=()=>这个函数,如果bind了,就没有问题

onPress={() => this._onPress(rowData)}>这个就是没有用到this._onPress.bind(this),而是用的fun=()=>{},我的上一篇文章说的bind的问题

_renderRow(rowData) {
    return <TouchableHighlight
        underlayColor='#008b8b'
        onPress={() => this._onPress(rowData)}>
        <View style={[styles.rowStyle, {flexDirection: 'row', justifyContent: 'space-between'}]}>
            <View style={{flex: 1}}>
                <Text style={styles.rowText}>{rowData.title}</Text>
                <View style={{flexDirection: 'row', marginTop: 10, justifyContent: 'space-between', alignItems: 'flex-end'}}>
                    <View style={{flexDirection: 'row', alignItems: 'center'}}>
                        <Image
                            style={{width: 20, height: 20, borderRadius: 10, marginRight: 5}}
                            source={{uri: rowData.user.avatarLarge}}
                        />
                        <Text style={styles.other}>{rowData.user.username}</Text>
                        <Text style={styles.other}>{Moment(rowData.createAt).fromNow()}</Text>
                    </View>
                    <Text style={[styles.other, {}]}>{rowData.commentsCount} 个回复</Text>
                </View>
            </View>
            {
                rowData.screenshot ? <Image style={{width: 60}} source={{uri: rowData.screenshot}}/> : <View/>
            }
        </View>
    </TouchableHighlight>
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值