gpt4 book ai didi

reactjs - 无法从 antd react 库导入 Drawer 组件

转载 作者:行者123 更新时间:2023-12-04 15:56:03 28 4
gpt4 key购买 nike

我在我的 React 应用中使用了 antd 组件。在所有组件中,我在导入和使用 Drawer 组件时遇到困难。所有其他组件都工作正常。我的代码相当简单。

import React from 'react';
import { Layout, Menu, Button, Drawer } from 'antd';

export class MyDesign extends React.Component {
...
render() {
return (
<div>
<Button /> <-- works fine
<Drawer title="Test" visible={true}> <--- doesn't work
<p>Some contents...</p>
</Drawer>
</div>
);
}
}

这会导致以下控制台警告,从 webpackHotDevClient

中发出
'antd' does not contain an export named 'Drawer'.

这表明问题出在我的应用程序如何导入 antd,而不是 antd 本身。我无法在 codepen 上使用相同的最新稳定版本 "antd": "^3.7.3" 在一个小测试用例上重现该问题。

可能发生了什么?是否发生了某种我需要覆盖的选择性项目范围导入?

最佳答案

您的 node_modules 中似乎有旧版本的 antd,并且您只更新了 package.json 以包含最新版本,无需重新安装。

您可以删除 node_modules 并重新安装所有内容以获取 package.json 中列出的每个依赖项的所有版本:

rm -rf ./node_modules && npm install

关于reactjs - 无法从 antd react 库导入 Drawer 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51604086/

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