简体   繁体   English

如何导入包含函数的默认导出 object?

[英]How to import an default exported object containing functions?

If one file has an export default:如果一个文件具有导出默认值:

export default {
   function,
   function2
}

How can I import these two functions in a separate file?如何在单独的文件中导入这两个函数? When I try restructuring it with当我尝试用

import { function, function2 } from 'path'

I get an error saying function is not exported from 'path'我收到一条错误消息,提示 function 未从“路径”导出

Since it's a default export, you will have to do it like below由于它是默认导出,因此您必须像下面那样进行

export default {
   function1,
   function2
}

import Path from 'path';

Path.function1();
Path.function2();

Look into this ressource.看看这个资源。

Basically, you can achieve this, by writing:基本上,您可以通过编写以下代码来实现这一点:

export const myExport1 = function
export const myExport2 = function2

And then:接着:

import { myExport1, myExport2} from 'path'

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

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