我正在使用React Native,我想从不同的类调用一个函数,但当我试图这样做时,它显示出一些错误.
Class A
import B from './B.js';
class A extends Component {
_onItemPressed(item){
B.abc();
}
render() {
return (
<TouchableHighlight
underlayColor={Colors.colors.lightgrey}
style={{padding: 15}}
onPress={this._onItemPressed.bind(this)}>
<Text>Click Me !</Text>
</TouchableHighlight>
);
}
}
Class B
class B extends Component {
abc(){
alert('Hello World');
}
render() {
return (
<View>
<Text>Welcome to React Native</Text>
</View>
);
}
}
但按下A类"undefined is not a function (evaluating 'B.default._abc()')"中的按钮后会出现错误消息
请仔细阅读我的帖子,并提出一些解决方案.
谢谢