Reac native (1) 环境搭建
发布时间:2020-12-15 07:25:19 所属栏目:百科 来源:网络整理
导读:环境搭建:参考教程,讲的非常详细 2.接着运行项目文件,我也忘了我的第一个项目从哪下载下来的了,但是第一次用studio运行,一般会报 could not get batchedbridge make sure 这个错误, 解决步骤: - 在Android的src-main目录下,新建文件夹/包 assets; -
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */
import React,{ Component } from 'react';
import {
AppRegistry,StyleSheet,Text,View
} from 'react-native';
export default class HelloComponent extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
HelloComponent
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#F5FCFF',},welcome: {
fontSize: 20,textAlign: 'center',margin: 10,instructions: {
textAlign: 'center',color: '#333333',marginBottom: 5,});
AppRegistry.registerComponent('react1',() => HelloComponent);
导入:import HelloComponent from './HelloComponent'
使用:
render() {
return (
<View style={styles.container}>
<HelloComponent/>
</View>
);
}
注意,有三种定义组件的方式,所以也有三种导出组件的方式* (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |