报错:can't find variavle:Component .RN版本0.31



  • alt text
    最近再研究使用百度地图
    https://github.com/hufeng/BaiduMapKit

    使用如下代码
    index.android.js

    'use strict';
    
    import React, {
      AppRegistry,
      StyleSheet,
      Text,
      View,
    } from 'react-native';
    
    import BaiduMap from 'baidumapkit';
    
    
    class BaiduMapExample extends Component {
      render() {
        return (
          <View style={styles.container}>
          <Text style={styles.welcome}>
          React Native Baidu MapView!
          </Text>
          <BaiduMap
          style={{flex:1}}
          marker={[
            [39.963175, 116.440244],
            [39.903175, 116.490244],
            [39.923175, 116.490244],
            [39.953175, 116.490244]]}
            mode={2} //1. 普通 2.卫星
            trafficEnabled={true}z
            heatMapEnabled={true} //城市实时交通热力图
            />
            </View>
            );
          }
        }
    
        var styles = StyleSheet.create({
          container: {
            flex: 1,
            justifyContent: 'center',
            alignItems: 'center',
            backgroundColor: '#F5FCFF',
          },
          welcome: {
            fontSize: 20,
            color: 'red',
            textAlign: 'center',
            margin: 10,
          }
        });
    
        AppRegistry.registerComponent('AwesomeProj', () => BaiduMapExample);
    

    MainActivity .java

    package com.awesomeproject;
    
    import com.facebook.react.ReactActivity;
    
    public class MainActivity extends ReactActivity {
    
        /**
         * Returns the name of the main component registered from JavaScript.
         * This is used to schedule rendering of the component.
         */
        @Override
        protected String getMainComponentName() {
            return "AwesomeProj";
        }
    }
    

    项目是使用react-native init创建的
    配置信息

    {
      "name": "AwesomeProject",
      "version": "0.0.1",
      "private": true,
      "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start"
      },
      "dependencies": {
        "baidumapkit": "^1.1.0",
        "react": "15.2.1",
        "react-native": "0.31.0",
        "react-native-amap-location": "^0.0.4"
      }
    }
    

    还有就是使用debug时会提示

    E:\project\AwesomeProject\node_modules\react-native\Libraries\JavaScriptAppEngine\Initialization\Ex…:61 Module AppRegistry is not a registered callable module.

    如果还需要其他信息,请提出

    感谢各位



  • 已解决

    import React, { Component } from 'react';
    忘了导入component


登录后回复