gpt4 book ai didi

javascript - 为什么 import { Thing } 有效但 import Thing 不起作用?

转载 作者:行者123 更新时间:2023-12-03 01:19:10 26 4
gpt4 key购买 nike

我正在观看 Pluralsight 上的一些培训视频,所以我一定会选择这个。但我也在做带薪工作(凭借 10 年的 Rails 经验)。这出现在 React 中,其中 import Link from 'react-router-dom'只能用作 import { Link } from 'react-router'dom 。另外,我喜欢在 SO 上检查事情是否正确。请原谅:)

最佳答案

这是命名导入和默认导入之间的区别:

import { Link } from 'react-router-dom'; // import the export named Link
import Link from 'react-router-dom'; // import the default export

为了进一步说明,如果您看一下 the file which handles the exports from react-router-dom ,您会看到有很多命名导出,但没有默认导出。如果有默认值,则:

import Link from 'react-router-dom';

将导入默认导出并将其命名为Link

关于javascript - 为什么 import { Thing } 有效但 import Thing 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51841744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com