【问题标题】:component is not defined react native组件未定义反应原生
【发布时间】:2019-06-21 13:35:09
【问题描述】:

我创建了一个空页面并尝试将另一个页面的组件导入到空页面中。

App.js

从 'react' 导入 React, {Component}; 从 './app.json' 导入 {name as appName};

进口{

    View,
    Text,
    StyleSheet,
    TextInput,
    Button,
    TouchableOpacity,
    AppRegistry

} 来自'react-native';

从“./Login”导入登录;

函数验证() {

alert("Button Clicked...")
console.log("Hello world!")

}

导出默认类 App 扩展组件{

render(){

    return(


        <Login />

        );

}

}

const 样式 = StyleSheet.create({

container: {

    // justifyContent: 'center',
    // alignItems: 'center',
    backgroundColor: '#af522a',
    flex: 1

},
txtText: {

    textAlign: 'center',
    fontSize: 25,
    color: '#9daf2a'

},
txtInput: {

    height: 45,
    borderColor: '#9daf2a',
    borderWidth: 3,
    marginTop: 75,
    padding: 12,
    backgroundColor: '#FFFFFF',
    marginLeft: 16,
    marginRight: 16,
    borderRadius: 15
},
txtInput2: {

    height: 45,
    borderColor: '#9daf2a',
    borderWidth: 3,
    padding: 12,
    backgroundColor: '#FFFFFF',
    marginLeft: 16,
    marginRight: 16,
    marginTop: 24,
    borderRadius: 15

},
loginScreenButton:{
marginRight:40,
marginLeft:40,

marginTop:45, 填充顶部:10, paddingBottom:10, 背景颜色:'#593eb2', 边界半径:10, 边框宽度:1, 边框颜色:'#fff' }, 登录文本:{ 颜色:'#fff', 文本对齐:'中心', 填充左:10, paddingRight : 10 }

})

登录.js

从 'react' 导入 React, {component}; 导入{

View,
TextInput,
StyleSheet

}来自'react-native';

导出默认类登录扩展组件{

render(){


    return(

        <View style = {styles.container}>
        </View>

        )

}

}

const 样式 = StyleSheet.create({

container: {background: "#44c41d", flex: 1}

})

错误

我刚刚开始使用 react-native 并且没有那么多知识。所以,请告诉我是否有人有任何解决方案。

提前致谢。

【问题讨论】:

    标签: react-native-ios


    【解决方案1】:

    在您的 Login.js 中,您使用小写组件,

    import React, {component} from 'react'
    

    将其转换为大写。

    import React, {Component} from 'react'; 
    

    【讨论】:

    • 确实执行了您的建议,但仍然没有工作。
    猜你喜欢
    • 2019-07-30
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多