【问题标题】:Named export and default export in the same file同一个文件中的命名导出和默认导出
【发布时间】:2016-10-17 12:42:32
【问题描述】:

我正在尝试将默认导出和命名导出放在同一个文件中。示例:

// file name : utils/fetch
export default fetchUtil;

module.exports = {
    fetch : fetchUtil,
    post,
    put,
    get,
};

// import code
import fetch from 'utils/fetch';

我的代码使用 webpack 构建得很好,但是在浏览器中我得到了错误:

fetchInit.js:27 Uncaught TypeError: (0 , _fetch2.default) 不是函数

我是否遗漏了什么,或者这不是在同一个文件中进行默认和命名导入的方法?

【问题讨论】:

    标签: javascript import


    【解决方案1】:

    在这里找到解决方案:http://exploringjs.com/es6/ch_modules.html

    基本上,我不得不这样做

    export default fetchUtil
    export {fetchUtil as fetch, post, put, get}
    

    【讨论】:

    • export {a as default, b as c, d, e, f};
    猜你喜欢
    • 2022-01-18
    • 2016-08-02
    • 2019-09-07
    • 2016-12-03
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 2018-08-26
    • 1970-01-01
    相关资源
    最近更新 更多