gpt4 book ai didi

javascript - 在不导入的情况下导出组件时出错

转载 作者:行者123 更新时间:2023-11-30 14:49:40 25 4
gpt4 key购买 nike

以下是我的文件:

定价.js

import React, { Component } from 'react';
import { Table } from 'react-bootstrap';

class Pricing extends Component {
render() {
return (
<Table striped bordered condensed>
<thead>
<th></th>
<th>Community</th>
<th>Business</th>
<th>Enterprise</th>
</thead>
<tbody>
<tr>
<td>Cost</td>
<td>Free</td>
<td>Free</td>
<td>Free</td>
</tr>
</tbody>
</Table>
);
}
}

export default Pricing;

索引.js

export { Pricing }  from './Pricing';

主要.js

import React from 'react';
import { Switch, Route } from 'react-router-dom';
import Pricing from '../../pages/Pricing';

const Main = () => (
<main>
<Switch>
<Route path='/pricing' component={Pricing}/>
</Switch>
</main>
)

export default Main;

我收到以下错误:

35:70-77 “在‘../../pages/Pricing’中找不到导出‘默认’(导入为‘定价’)

最佳答案

您可以选择以下任一选项

首先从您的index.js 文件中导入然后导出定价组件

import Pricing from './Pricing'
export { Pricing }

否则您需要像这样导出默认组件

export { default as Pricing }  from './Pricing';

或将导出更改为 Pricing.js 中的命名导出

export { Pricing };
export default Pricing;

像这样使用它

export { Pricing }  from './Pricing';

如果您希望从您的 index.js 中将定价组件导出为默认导出,您可以编写

export {default} from './Pricing';

关于javascript - 在不导入的情况下导出组件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48359823/

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