代码之家  ›  专栏  ›  技术社区  ›  Emo

导入Ant设计组件无效

  •  1
  • Emo  · 技术社区  · 7 年前

    我对我现在遇到的这个问题感到震惊。我所有的逻辑都停止了。有些东西开始不起作用了,我没有改变任何东西。我的意思是,我甚至在生产中使用了相同的代码,但在本地,它开始不起作用,完全是凭空产生的。即使当我回到以前的提交,我百分之百确定它是有效的,但它不起作用。

    流星,反应,蚂蚁设计。请帮忙!

    错误是: ReferenceError: Layout is not defined

    代码为:

    import React from 'react';
    import Blaze from 'meteor/gadicc:blaze-react-component';
    import { Link } from 'react-router-dom';
    import { Layout, Menu } from 'antd';
    const { Header, Content, Footer } = Layout;
    
    class LayoutContainer extends React.Component {
      render() {
    
        const { match, children } = this.props;
        const pathname = match.location.pathname;
    
        return (
          <Layout className="layout">
            <Header style={{backgroundColor: '#fff'}}>
              <Menu
                selectedKeys={[pathname]}
                mode="horizontal"
                style={{ lineHeight: '64px', float: 'right' }}
              >
                <Menu.Item key={'/'}>
                  <Link to="/">Home</Link>
                </Menu.Item>
                <Menu.Item key={'/create-a-gathering'}>
                  <Link to="/create-a-gathering">Create</Link>
                </Menu.Item>
              </Menu>
              <div className="logo" />
              <Blaze template="loginButtons" />
            </Header>
            <Content style={{ marginTop: 20 }}>
              {children}
            </Content>
            <Footer style={{ textAlign: 'center' }}>
    
            </Footer>
          </Layout>
        )
      }
    }
    
    export default LayoutContainer;
    
    3 回复  |  直到 7 年前
        1
  •  4
  •   Afaq Ahmed Khan Hong Tang    6 年前

    这是一个报告的antd问题 Reference Error: Layout not defined

    解决这个问题的一个简单方法是像这样导入布局

     import Layout from 'antd/lib/layout'
    

    或者您也可以通过将antd版本更新到“^3.2.2”或更高版本来进行排序

        2
  •  1
  •   Emo    6 年前

    我早就应该回答这个问题了,但这里是这样的:

    正如阿法克·艾哈迈德·汗(Afaq Ahmed Khan)指出的那样:

    import { Layout, Menu } from 'antd/lib';
    

    这就是答案。

    我猜两个包中的巴贝尔互相冲突,因此 '/lib' 到根目录 '/' alias不工作。

        3
  •  0
  •   xSkrappy    7 年前

    这可以通过删除节点模块文件夹,然后重建整个项目来解决。