首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在标题菜单项中使用PopOver

无法在标题菜单项中使用PopOver
EN

Stack Overflow用户
提问于 2019-06-09 21:29:02
回答 1查看 334关注 0票数 0

我想创建一个带有popover组件的页眉

代码语言:javascript
复制
import React from "react";
import { Layout, Menu, Button } from "antd";
const { Header, Popover } = Layout;
const { SubMenu } = Menu;

const Index = (props) => {
    const content = (
        <menu>
            <Menu.Item>Menu</Menu.Item>
            <SubMenu title="SubMenu">
                <Menu.Item>SubMenuItem</Menu.Item>
            </SubMenu>
        </menu>
    );
    return (
        <Header>
            <div
                className=" float-left text-light"
                style={{ fontSize: "1.4rem" }}
            >
                Shonode
            </div>
            <Menu
                theme="dark"
                mode="horizontal"
                defaultSelectedKeys={["2"]}
                style={{ lineHeight: "64px" }}
            >
                <Menu.Item key="1">nav 1</Menu.Item>
                <Menu.Item key="2">nav 2</Menu.Item>
                <Menu.Item key="3">sda</Menu.Item>

            </Menu>
        </Header>
    );
};

export default Index;

这个组件可以工作,但是当我用粘贴项目3

代码语言:javascript
复制
<Menu.Item key="3">
       <Popover content={content}title="Title" trigger="hover">
        <Button>Hover me</Button>
    </Popover>
</Menu.Item>

我得到了错误

元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但got: undefined。您可能忘记了从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-09 23:16:11

问题是您试图从Layout导入Popover,而Layout不是Layout的组件

而不是:

代码语言:javascript
复制
import { Layout, Menu, Button } from "antd";
const { Header, Popover } = Layout; 

尝试:

代码语言:javascript
复制
import { Popover, Layout, Menu, Button } from "antd";
const { Header } = Layout;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56514976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档