ES6如何从一个文件导出所有项目 [英] ES6 how to export all item from one file

查看:452
本文介绍了ES6如何从一个文件导出所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从另一个文件导出文件的所有方法.

I want to export all methods of a file from another file.

当前,我正在执行此操作,并且它可以正常工作.如何将以下两个合并为1个导出表达式

currently I am doing this, and it works. How can I merge below two into 1 export expression

import  * as db  from './web/query';
export default db;

我尝试了以下1行写输出,但都失败了

I tried below written 1 line exports but all failed

export *   from './web/query';  //==error
export *  as default  from './web/query';  //==error
export *  as {default}  from './web/query';  //==error
export from from './web/query'; //== error
export default from './web/query'; //== error

错误提示

import db from '../db/index';

db在这里未定义.但是第一种方法有效

db is undefined here. However the the first methods works

文件'./web/query'内部看起来像

export function foo(){}
export function baar(){}

推荐答案

您不能在ES2016中使用.要创建模块名称空间对象,您需要在当前模块作用域中为其赋予一个标识符(例如db),然后重新导出该标识符.没办法解决.

You cannot in ES2016. To create a module namespace object, you need to give it an identifier (like db) in your current module scope, and then re-export that. There's no way around it.

但是,在阶段1 提案中添加了export * as default from …语法你在尝试.

There is however a stage 1 proposal to add the export * as default from … syntax you were trying.

这篇关于ES6如何从一个文件导出所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆