我在导入UI库时遇到问题,我在使用蚂蚁设计库时遇到了问题,所以我决定尝试其他的库,现在我在导入Grommet时遇到问题。
我在做什么错?我根据文档添加了依赖性,并添加了文档中包含的示例,但仍然无法正常工作。
我正在尝试执行this code from documentation
但是看起来根本不一样
我使用codeandbox.io,here is link for the code on it
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import Heading from "grommet/components/Heading";
import Box from "grommet/components/Box";
import Header from "grommet/components/Header";
import Title from "grommet/components/Title";
import Search from "grommet/components/Search";
import Menu from "grommet/components/Menu";
import Anchor from "grommet/components/Anchor";
import "grommet-css";
class HelloWorldApp extends React.Component {
render() {
return (
<div>
<Header>
<Title>Sample Title</Title>
<Box flex={true} justify="end" direction="row" responsive={false}>
<Search
inline={true}
fill={true}
size="medium"
placeHolder="Search"
dropAlign={{right: "right"}}
/>
<Menu dropAlign={{right: "right"}}>
<Anchor href="#" className="active">
First
</Anchor>
<Anchor href="#">Second</Anchor>
<Anchor href="#">Third</Anchor>
</Menu>
</Box>
</Header>
<Box>
<Heading>
Hello, I'm a Grommet Component styled with
<a href="https://www.npmjs.com/package/grommet-css">grommet-css</a>
</Heading>
</Box>
</div>
);
}
}
var element = document.getElementById("root");
ReactDOM.render(<HelloWorldApp />, element);
答案 0 :(得分:1)
因此,根据您的代码:
<Menu dropAlign={{right: "right"}}>
缺少icon属性,如果没有该属性, Menu组件将直接呈现 Anchor ,
菜单项组件。
为所选图标添加导入,即:操作(来自示例)
import Actions from 'grommet/components/icons/base/Actions';
将图标属性添加到“菜单”组件:
<Menu
icon={<Actions />}
dropAlign={{ right: 'right' }}
>
<Anchor href="#" className="active">First</Anchor>
<Anchor href="#">Second</Anchor>
<Anchor href="#">Third</Anchor>
</Menu>
这是一个 codesandbox.io链接,可解决您的问题:
https://codesandbox.io/s/237xo7y48p