【发布时间】:2016-03-17 08:05:39
【问题描述】:
我正在做一个新项目,之前我在做类似 2 的事情,可以毫无问题地导入 get 函数。不知何故,今天 2 给了我 undefined 但 1 给了我正确的答案。有谁知道这是为什么?
ps:我的node版本是4.0.0
import api from "../../utils/APIUtils"; // --- 1
let get = api.get;
console.log(get); // function
import { get } from '../../utils/APIUtils'; // --- 2
console.log(get); // undefined now..
export default const APIUtils = {
get(endpoint, query, options, done) { done(123) }
}
p.s:我在这里看到了类似 1 的用法,它们工作正常。
导出默认xxx: https://github.com/gpbl/isomorphic500/blob/master/src/utils/APIUtils.js
从括号中导入:https://github.com/gpbl/isomorphic500/blob/master/src/services/photo.js
【问题讨论】:
-
为什么是 what? 1 和 2 表示不同的东西,它们不能互换使用。
-
行为正确。如果它真的有效,那么它是不正确的。你不需要
const APIUtils =btw。
标签: ecmascript-6 babeljs