简体   繁体   English

如何在snack.expo.io中导入/导出js文件

[英]how to import/export js file in snack.expo.io

please I'm new to react native and I am working on a project on snack.expo.io They seem fine to me but I wish to connect a js (component1.js) file to the parent App.js file but it keeps giving me these errors. 请我是新来回应本机,我正在开发关于snack.expo.io的项目他们似乎很好,但我希望将一个js(component1.js)文件连接到父App.js文件,但它一直给予我这些错误。

Device: (1069:6932) Failed to install module '/component1': Failed to download module '~component1@latest' imported from App.js 设备:(1069:6932)无法安装模块'/ component1':无法下载从App.js导入的模块'~component1 @ latest'

Here is my App.js file: 这是我的App.js文件:

 import React from 'react'; import { View, StyleSheet } from 'react-native'; import { Component1 } from 'expo'; // You can import from local files // or any pure javascript modules available in npm export default class App extends React.Component { render() { return ( <View style={styles.container}> <Component1 /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: '#ecf0f1', }, }); 

And I want to get my result from my "component1.js", which is below: 我想从我的“component1.js”得到我的结果,如下所示:

 import React, { Component } from 'react'; import { Text, View, StyleSheet, TouchableOpacity } from 'react-native'; export default class Component1 extends Component { addRow= ()=>{ alert("Chat Unavailable"); } render() { return ( <View style={styles.part}> <TouchableOpacity style={styles.btn} onPress={this.addRow}> <Text style={styles.plus}> + </Text> </TouchableOpacity> </View> ); } } const styles = StyleSheet.create({ part: { flex: 1, alignItems: 'center', justifyContent: 'center', }, btn: { position: 'absolute', width:50,height:50, backgroundColor:'#00FF00', borderRadius:50, bottom:10,right:10, alignItems:'center', justifyContent:'center', }, plus: { color:'white', fontSize: 25, } }); 
Please bear with me, I hope I asked my question correctly. 请耐心等待,我希望我能正确地提出我的问题。 Please be Nice 请友好一点

You can only import API's from Expo's SDK when you do 您只能从Expo的SDK中导入API

import { /* Something here */ } from 'expo'; .

To import your own components, you only need to import them from the directory they are in. 要导入自己的组件,只需从它们所在的目录中导入它们。

If it is in the same directory as App.js then it would be: 如果它与App.js在同一目录中,那么它将是:

import Component1 from './Component1';

If you have a src directory or some other directory, it would look like: 如果你有一个src目录或其他目录,它看起来像:

import Component1 from './src/Component1';

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

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