javascript - react 写的component怎么加到react-native的view里面?
PHP中文网
PHP中文网 2017-04-11 09:45:07
[JavaScript讨论组]

chart.js

import ReactHighcharts from 'react-highcharts';
export default  class Pie extends React.Component {
  render() {
let config={
 title:{text:'browser'},
 series: [{

                type: 'pie',
                name: 'SLICE',
                data: [
                    ['Safari',    8.5],
                    ['Opera',     6.2],
                    ['Others',   0.7]
                ]
            }]
};

    return <ReactHighcharts config={config} ref="chart"></ReactHighcharts>;
  }
}

index.android.js


import React, {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  View
} from 'react-native';
import  Chart from './chart.js';

class AwesomeProject extends Component {
  render() {
    return (
      <View style={styles.container}>
<Chart   style={styles.welcome}  />
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.android.js
        </Text>
        <Text style={styles.instructions}>
          Shake or press menu button for dev menu
        </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: 'red',
    marginBottom: 5,
  },
});




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

手机运行报错 Expected a compoment class ,got p

chart.js 如果用在电脑浏览器里就能正常显示

PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号