导出模块(元素类型无效,期望一个字符串)

时间:2020-12-18 16:34:17

i call to Trafik.js in index page but it doesnt run and i took wrong , i dont know why...

我在索引页面中调用Trafik.js,但它没有运行,我错了,我不知道为什么......

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of dene1.

元素类型无效:期望一个字符串(用于内置组件)或一个类/函数(用于复合组件)但得到:object。检查dene1的render方法。

1-index.android.js

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableHighlight,
  Navigator
} from 'react-native';

import Trafik from './Trafik'


var dene1 = React.createClass({

render : function(){

return  <View style = {[style.container,this.border('red')]} >

{this.header()}

{this.middle()}

{this.footer()}

<Trafik/>

        </View>

}, //render

header:function(){
 return   <View style = {[style.header,this.border('yellow')]}>
 <View style={[style.teklifBtn,this.border('blue')]}>
<Text>
Teklifler
</Text>
 </View>
  <View style={[style.mesajBtn,this.border('blue')]}>
  <Text>
Mesajlar
</Text>
 </View>

         </View>    

    },
middle:function(){
 return   <View style = {[style.middle,this.border('green')]}>
<Text>
middle
</Text>
         </View>    

},

footer:function(){
 return   <View style = {[style.footer,this.border('black')]}>
 <TouchableHighlight style={[style.kaskoBtn,this.border('blue')]}>
<Text>
kasko
</Text>
 </TouchableHighlight>
  <TouchableHighlight  underlayColor='red'  style={[style.trafikBtn,this.border('blue')]}>
  <Text>
trafik
</Text>
 </TouchableHighlight>
  <TouchableHighlight style={[style.yanginBtn,this.border('blue')]}>
<Text>
yangin
</Text>
 </TouchableHighlight>
  <TouchableHighlight style={[style.seyahatBtn,this.border('blue')]}>
  <Text>
seyahat
</Text>
 </TouchableHighlight>

         </View>    

},
border:function(color){
    return {
    borderColor : color,
    borderWidth: 4
    }
},


}) ;//dene1

var style = StyleSheet.create({
container :{
        flex:1,

    },
    header : {
        flex :0.9,
        flexDirection:'row',


},
    middle : {
        flex :3,
        flexDirection:'row',
        justifyContent:'center',
         alignItems: 'center',

    },
    footer:{

        flex :4,
        flexDirection:'column',


    },
        teklifBtn:{

        flex :1,
        justifyContent:'center',
         alignItems: 'center',
         backgroundColor:'red'

    },
        mesajBtn:{

        flex :1,
         justifyContent:'center',
         alignItems: 'center',

    },
        kaskoBtn:{

        flex :1,
         justifyContent:'center',
         alignItems: 'center',


    },
        trafikBtn:{

        flex :1,
         justifyContent:'center',
         alignItems: 'center',

    },
        yanginBtn:{

        flex :1,
         justifyContent:'center',
         alignItems: 'center',

    },
        seyahatBtn:{

        flex :1,
         justifyContent:'center',
         alignItems: 'center',

    },



})

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

2.trafik.js

'use strict';

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


var Trafik = React.createClass({
render : function(){
return  
<Text>
trafik sayfası
</Text>
}
}) ;//dene1

module.export = Trafik;

1 个解决方案

#1


1  

Try this in Trafik.js last line replace module.export = Trafik; with export default Trafik;

在Trafik.js最后一行替换module.export = Trafik;出口默认Trafik;

#1


1  

Try this in Trafik.js last line replace module.export = Trafik; with export default Trafik;

在Trafik.js最后一行替换module.export = Trafik;出口默认Trafik;