1.4 KiB
1.4 KiB
id, challengeType, forumTopicId, title
id | challengeType | forumTopicId | title |
---|---|---|---|
587d7b8d367417b2b2512b59 | 1 | 301205 | 导入一个默认的导出 |
Description
export default
的用法。还需要一种import
的语法来导入默认的导出。
在下面的例子里有一个add
函数, 它在"math_functions"
文件里默认被导出。来看看来如何导入它:
import add from "./math_functions.js";
这个语法只有一处不同的地方 —— 被导入的add
值,并没有被花括号{}
所包围。与导出值的方法不同,导入默认导出的写法仅仅只是简单的将变量名写在import
之后。
Instructions
"math_functions"
文件中默认导出的subtract
值。
Tests
tests:
- text: 正确导入<code>export default</code>方法导出的值。
testString: assert(code.match(/import\s+subtract\s+from\s+('|")\.\/math_functions\.js\1/g));
Challenge Seed
// add code above this line
subtract(7,4);
Solution
import subtract from "./math_functions.js";
// add code above this line
subtract(7,4);