加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react native 学习笔记之Props

发布时间:2020-12-15 03:22:46 所属栏目:百科 来源:网络整理
导读:在IOS或者Android中,通常一个类都有成员变量和函数,成员变量也可以叫成员属性。在props的例子程序中,可以 把Image看成系统定义好的类,而Greeting看成是我们自己定义的一个类,在react native中称为组件 (Component)。那么这样理解的话,source={pic}

在IOS或者Android中,通常一个类都有成员变量和函数,成员变量也可以叫成员属性。在props的例子程序中,可以

把Image看成系统定义好的类,而Greeting看成是我们自己定义的一个类,在react native中称为组件

(Component)。那么这样理解的话,source={pic} 就是给Image的成员变量source赋值了,只是react native的语法

需要用{}括起来。同样就不难理解style={{width: 193,height: 110}}。


其它的可以参看我代码中的注释,可以帮助理解。
import React,{ Component } from 'react';
import { AppRegistry,Image } from 'react-native';

class Bananas extends Component {
  render() {
    let pic = {
      uri: 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg'
    };
    return (
      <Image source={pic} style={{width: 193,height: 110}} />
    );
  }
}

AppRegistry.registerComponent('Bananas',() => Bananas);


Text,21)">View } from Greeting Component {
  render() {
    Text>Hello {this.props.name}!</Text>//引用属性(成员变量));
  }
}

LotsOfGreetings View style={{alignItems: 'center'}}>
        <Greeting name='Rexxar' />//给属性(成员变量)name赋值<'Jaina' />
        <'Valeera' />
      </View>
    );
  }
}

'LotsOfGreetings',21)">LotsOfGreetings);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读