React Native_学习01

作者: Mark_大东 | 来源:发表于2018-08-08 11:53 被阅读2次

之前创建RN项目会出现index.ios.js、index.android.js ;现在创建的react native init xxxx 的项目只有index.js,这样就可以同时做多平台开发;

下面会谈到两个问题:

  1. View config not found for name 怎么解决
  2. 组建之间的项目引用

View config not found for name 解决方式:js文件的首字母命名要大写,如:one.js -------->One.js

组建之间项目引用:如:App.js进入One.js

One.js代码如下:

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

//定义一个组件  ES6
export default class One extends Component{
    render(){
        return(
            <Text style={{fontSize:20,backgroundColor: '#F5FCFF'}}>你好呀.{this.props.name}</Text>
        );
    };
}


/** 函数时的方式定义组件
*   无状态,不能使用this
**/
 function One(props) {
     return <Text style={{fontSize:20,backgroundColor: '#F5FCFF'}}>你好呀.{props.name}</Text>
 }
 module.exports = One;

App.js引入外部组件的方式如下:

import One from './One'

export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
          <One
              name = '123'
          />
      </View>
    );
  }
}

相关文章

网友评论

    本文标题:React Native_学习01

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