繁体   English   中英

为什么无法识别我的Index.js文件?

[英]Why won't my Index.js file be recognized?

我制作了一个单独的Index.js文件,以容纳要在整个正在创建的应用程序中导出的所有组件。 我以为我要使用的文件路径是正确的,但是...

我收到一条错误消息:

无法解决
'/ User / user / projects / Something / src / components / components'作为文件
也不作为文件夹(空)

目录路径的屏幕截图

我怎样才能解决这个问题?

这是LoginForm.js

import React, { Component } from 'react';
import { TouchableOpacity, StyleSheet, View, Text ,Button } from 'react-native';
import { UserInput } from './components';

class LoginForm extends Component {
  render() {
    return(
      <View style={styles.container}>
        <UserInput/>
          <TouchableOpacity style={styles.button}>
            <Button
              title="Press Me"
            />
          </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingHorizontal: 10
  },

  button: {
    alignItems: 'center',
    backgroundColor: '#DDDDDD',
    padding: 10
  }
});

export default LoginForm;

这是Index.js

export * from './UserInput';
export * from './LoginForm';

LoginForm.js的当前工作目录中,没有components文件夹。 从脚本中,您需要LoginForm组件中的UserInput组件。

你可以简单地做到

import { UserInput } from './UserInput';

当您要在其他目录的组件目录中导入文件夹的选定组件时,正确使用components文件夹的index.js

更新:

LoginForm组件中

import  UserInput  from './UserInput'; //default  export

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM