Javascript 反应本机预期字符串,但得到对象
我正在尝试导入index.android.js中的登录模块,但它似乎不起作用?渲染方法有什么问题 login.js位于/screens/login.js中 react本机版本“0.39.2” index.android.jsJavascript 反应本机预期字符串,但得到对象,javascript,android,react-native,Javascript,Android,React Native,我正在尝试导入index.android.js中的登录模块,但它似乎不起作用?渲染方法有什么问题 login.js位于/screens/login.js中 react本机版本“0.39.2” index.android.js 'use strict'; import React, { Component } from 'react'; import { AppRegistry} from 'react-native'; //login module var LoginScreen = requ
'use strict';
import React, { Component } from 'react';
import { AppRegistry} from 'react-native';
//login module
var LoginScreen = require('./screens/login');
var app = React.createClass({
render: function() {
return (
<LoginScreen />
);
}
});
AppRegistry.registerComponent('app', () => app);
“严格使用”;
从“React”导入React,{Component};
从“react native”导入{AppRegistry};
//登录模块
var LoginScreen=require(“./screens/login”);
var app=React.createClass({
render:function(){
返回(
);
}
});
AppRegistry.registerComponent('app',()=>app);
/screens目录下的login.js
'use strict';
import React, { Component } from 'react';
var Button = require('react-native-button');
import {
AppRegistry,
StyleSheet,
View,
Text,
TextInput
} from 'react-native';
var Login = React.createClass({
getInitialState: function() {
return {
username: '',
password: ''
}
},
_loginClick: function(event){
console.log('login tapped');
},
render: function() {
return (
<View style={styles.container}>
<View style={styles.inputs}>
<View style={styles.inputContainer}>
<TextInput
style={[styles.input, styles.whiteFont]}
placeholder="Username"
placeholderTextColor="#FFF"
value={this.state.username}
/>
</View>
<View style={styles.inputContainer}>
<TextInput
password={true}
style={[styles.input, styles.whiteFont]}
placeholder="Pasword"
placeholderTextColor="#FFF"
value={this.state.password}
/>
</View>
<View style={styles.forgotContainer}>
<Text style={styles.greyFont}>Forgot Password</Text>
</View>
</View>
<View style={styles.signin}>
<Text style={styles.whiteFont}>Sign In</Text>
<Button
style={{borderWidth: 1, borderColor: 'blue'}}
onPress={this._loginClick}>
Login
</Button>
</View>
<View style={styles.signup}>
<Text style={styles.greyFont}>Don't have an account?<Text style={styles.whiteFont}> Sign Up</Text></Text>
</View>
</View>
);
},
});
module.exports = Login;
“严格使用”;
从“React”导入React,{Component};
var-Button=require('react-native-Button');
进口{
评估学,
样式表,
看法
文本,
文本输入框
}从“反应本机”;
var Login=React.createClass({
getInitialState:函数(){
返回{
用户名:“”,
密码:“”
}
},
_loginClick:函数(事件){
log('login-tapped');
},
render:function(){
返回(
忘记密码
登录
登录
没有帐户?注册吧
);
},
});
module.exports=登录;
问题在于按钮组件,请将其移除。其次,您也缺少样式。问题在于您的按钮组件,请将其删除。其次,您也缺少样式。假设react native按钮
所指的是,那么您导入的组件不正确。应该是:
import Button from 'react-native-button';
这是因为Button.js使用
export default class
而不是module.export
导出组件。因此,您应该使用import
而不是require()
。有关导出的详细信息假设引用了反应本机按钮
,则您导入的组件不正确。应该是:
import Button from 'react-native-button';
这是因为Button.js使用export default class
而不是module.export
导出组件。因此,您应该使用import
而不是require()
。有关导出的更多信息更改此项:
var-Button=require('react-native-Button');
为此
从“反应本机按钮”导入按钮;
更改此选项:
var-Button=require('react-native-Button');
为此
从“反应本机按钮”导入按钮;
您在logcat中是否遇到异常?它是否说明错误发生在哪一行?您在logcat中是否遇到异常?它是否说明错误发生在哪一行?