react - 7. 视图中的component

栏目: IOS · Android · 发布时间: 7年前

内容简介:每个extends React.Component的class, 都是一个component ,可以直接用在 jsx里。非常类似于 .jsp,   .vue,  Rails 中的partial.例如,我 自定义一个这样的component

每个extends React.Component的class, 都是一个component ,可以直接用在 jsx里。

非常类似于 .jsp,   .vue,  Rails 中的partial.

例如,我 自定义一个这样的component

screens/ViewComponent.js

import React,  { Component} from 'react';
import {Image, Platform, StyleSheet, Text, View, Button} from 'react-native'

class Book extends Compent{
  render (){
    return(
      <View style={{alignItems: 'center'}}>
        <Text> 《{this.props.name}》
        </Text>
      </View>
    )
  }
}

export default class MyFavorateBooks extends Component{

  render(){
    return(
      <View>
        <Book name="三体1:" />
        <Book name="三体2:黑暗森林" />
        <Book name="三体3:死神永生" />
      </View>
    )
  }
}

可以看到,<Book name='...'/> 中的name, 就是 在   class Book extends ...代码块中使用的 this.props.name


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Learning Python, 5th Edition

Learning Python, 5th Edition

Mark Lutz / O'Reilly Media / 2013-7-6 / USD 64.99

If you want to write efficient, high-quality code that's easily integrated with other languages and tools, this hands-on book will help you be productive with Python quickly. Learning Python, Fifth Ed......一起来看看 《Learning Python, 5th Edition》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具