[英]Attempted import error: 'ApiRequests' is not exported from './ApiRequests'
I am new in js and react,so:我是 js 新手并做出反应,所以:
i try to export js function:我尝试导出 js function:
App.js:应用程序.js:
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { render } from 'react-dom';
import { LazyLog } from 'react-lazylog';
import 'bootstrap/dist/css/bootstrap.min.css';
import { Dropdown } from 'react-bootstrap';
import {ApiRequests} from './ApiRequests'
var textConst="";
var lines=ApiRequests.GetMockLogLines();
textConst=lines;
And ApiRequests.js:和 ApiRequests.js:
export function GetMockLogLines()
{
let logs=[""]
return logs;
}
So, when i compile js (o, my God) it breaks me:所以,当我编译 js(哦,我的上帝)时,它让我崩溃了:
Attempted import error: 'ApiRequests' is not exported from './ApiRequests'.
When i change it to:当我将其更改为:
import ApiRequests from './ApiRequests'
-> ->
Attempted import error: './ApiRequests' does not contain a default export (imported as 'ApiRequests').
So, i just want to get function from another file.所以,我只想从另一个文件中获取 function 。 What i do wrong?
我做错了什么?
And what difference between {} and without it? {} 和没有它有什么区别? (you can send me a link start to read,pls).
(你可以给我一个链接开始阅读,请)。
There is no function named Apirequests in your file.您的文件中没有名为 Apirequests 的 function。 The function you are exporting is
GetMockLogLines()
您要导出的 function 是
GetMockLogLines()
So your import should be所以你的进口应该是
import {GetMockLogLines} from './ApiRequests'
As for the importing difference betweent {} and without the curly braces is how you are exporting your stuff from your file.至于 {} 和没有大括号之间的导入区别是您如何从文件中导出内容。 There are two types of exports - Default export and named exports.
有两种类型的导出 - 默认导出和命名导出。 One can have only one default export per file and it has to be imported without the curly braces.
每个文件只能有一个默认导出,并且必须在没有花括号的情况下导入。
You can read more here - https://medium.com/@etherealm/named-export-vs-default-export-in-es6-affb483a0910您可以在此处阅读更多信息 - https://medium.com/@etherealm/named-export-vs-default-export-in-es6-affb483a0910
you need to import GetMockLogLines
directly as it is a named import.您需要直接导入
GetMockLogLines
,因为它是命名导入。 change your code to the following.将您的代码更改为以下内容。
import { GetMockLogLines } from './ApiRequests' var lines=GetMockLogLines();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.