【发布时间】:2016-06-07 22:02:07
【问题描述】:
我尝试使用 react native 读取 QRcode 然后我安装库
这是我的代码
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
NavigatorIOS,
} = React;
var QRCodeScreen = require('./QRCodeScreen');
var cameraApp = React.createClass({
render: function() {
return (
<NavigatorIOS
style={styles.container,{ width:100,height:500}}
initialRoute={{
title: 'Index',
backButtonTitle: 'Back',
component: Index,
}}
/>
);
}
});
var Index = React.createClass({
render: function() {
return (
<View style={styles.contentContainer}>
<TouchableOpacity onPress={this._onPressQRCode} >
<Text>Read QRCode</Text>
</TouchableOpacity>
</View>
);
},
_onPressQRCode: function() {
this.props.navigator.push({
component: QRCodeScreen,
title: 'QRCode',
passProps: {
onSucess: this._onSucess,
},
});
},
_onSucess: function(result) {
console.log(result);
},
});
var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
contentContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
AppRegistry.registerComponent('MyFirstReactapril', () => cameraApp);
但我收到此错误 undefined 不是对象(评估 'this.props.navigator.push')
我不知道它有什么问题,请帮忙。 或者有没有图书馆可以读取二维码并给我链接或字符串?
【问题讨论】:
-
嘿,您注册的是索引组件,而不是cameraApp,顺便说一句,将子组件放在顶部更好
-
@liupluto 没有改变,仍然有错误
标签: android npm react-native qr-code