【发布时间】:2018-06-15 02:20:53
【问题描述】:
我正在导入外部 js 文件并在组件中调用函数,但出现错误“获取我使用此代码但显示未定义不是对象(正在评估 _ApiHelper.ApiHelper.getPost)”
主登录文件代码
import React, { Component } from "react";
import Icon from "react-native-vector-icons/Ionicons";
import {
View,
StyleSheet,
Image,
TextInput,
TouchableOpacity,
Text,
Alert,
KeyboardAvoidingView
} from "react-native";
//
import { Search } from '../Search/Search';
import { ApiHelper } from '../../api/ApiHelper';
export default class Login extends Component {
static navigationOptions =
{
title: 'LoginActivity',
};
constructor(props) {
super(props);
//
//Obj = new ApiHelper();
//
this.state = {
userName: '',
password: '',
serverName:''
}
}
UserRegistrationFunction = () =>{
const { userName } = this.state ;
const { password } = this.state ;
const { serverName } = this.state ;
this.data = {
name: userName,
email: password,
password: serverName
}
alert(ApiHelper.getPost());
//Alert.alert(returndata);
}
导入文件代码
const ApiHelper = {
getPost:() => {
return 1;
}
}
export default ApiHelper;
我的代码有什么问题,我还清除了反应本机缓存和其他内容。 提前致谢。
【问题讨论】:
-
要么您导入了错误的文件,要么您没有显示代码的相关部分。或者,也许您没有复制/粘贴错误并打错了字。
-
我正在导入正确的文件
-
错误显示了对
getdata的调用,您的代码中未在此处显示。 -
原来你打错了。 :) 现在看看@mersocarlin 的回答。