React native 导出模块(元素类型无效,应为字符串)
我在索引页面中调用了Trafik.js,但它没有运行,我搞错了,我不知道为什么 元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:对象。检查React native 导出模块(元素类型无效,应为字符串),react-native,React Native,我在索引页面中调用了Trafik.js,但它没有运行,我搞错了,我不知道为什么 元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:对象。检查dene1的渲染方法 1-index.android.js import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, TouchableHighlight, Navigator } from
dene1
的渲染方法
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);
import React,{Component}来自'React';
进口{
评估学,
样式表,
文本,
看法
触控高光,
领航员
}从“反应本机”;
从“/Trafik”导入Trafik
var dene1=React.createClass({
render:function(){
返回
{this.header()}
{this.middle()}
{this.footer()}
},//渲染
标题:函数(){
返回
泰克利夫勒
梅萨杰拉尔
},
中间:函数(){
返回
中间的
},
页脚:函数(){
返回
卡斯科
特拉菲克
仰光
西亚哈
},
边框:功能(颜色){
返回{
边框颜色:颜色,
边框宽度:4
}
},
}) ;//密度1
var style=StyleSheet.create({
容器:{
弹性:1,
},
标题:{
弹性系数:0.9,
flexDirection:“行”,
},
中间:{
弹性:3,
flexDirection:“行”,
辩护内容:'中心',
对齐项目:“居中”,
},
页脚:{
弹性:4,
flexDirection:“列”,
},
teklifBtn:{
弹性:1,
辩护内容:'中心',
对齐项目:“居中”,
背景颜色:“红色”
},
mesajBtn:{
弹性:1,
辩护内容:'中心',
对齐项目:“居中”,
},
kaskoBtn:{
弹性:1,
辩护内容:'中心',
对齐项目:“居中”,
},
trafikBtn:{
弹性:1,
辩护内容:'中心',
对齐项目:“居中”,
},
yanginBtn:{
弹性:1,
辩护内容:'中心',
对齐项目:“居中”,
},
西亚哈特恩:{
弹性:1,
辩护内容:'中心',
对齐项目:“居中”,
},
})
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;
“严格使用”;
从“React”导入React,{Component};
进口{
文本,
看法
}从“反应本机”;
var Trafik=React.createClass({
render:function(){
返回
trafik sayfası
}
}) ;//密度1
module.export=Trafik;
在Trafik.js最后一行替换中尝试此操作
module.export=Trafik;
具有
导出默认Trafik 在Trafik最后一行尝试此操作,替换为导出默认Trafik;检查是否显示我将在trafik.js中写作?导出默认值=Trafik;或module.export.default=Trafik;或…导出默认Trafik;就这样,它解决了你的问题吗