【发布时间】:2017-12-21 13:56:21
【问题描述】:
我正在尝试从 react 语义 UI 实现交互式侧边栏,我从他们的网站上复制了代码,但我不太确定如何实现它:
import React, { Component } from 'react'
import { Sidebar, Segment, Button, Menu, Image, Icon, Header } from 'semantic-ui-react'
class SidebarLeftScaleDown extends Component {
state = { visible: false }
toggleVisibility = () => this.setState({ visible: !this.state.visible })
render() {
const { visible } = this.state
return (
<div>
<Button onClick={this.toggleVisibility}>Toggle Visibility</Button>
<Sidebar.Pushable as={Segment}>
<Sidebar as={Menu} animation='scale down' width='thin' visible={visible} icon='labeled' vertical inverted>
<Menu.Item name='home'>
<Icon name='home' />
Home
</Menu.Item>
<Menu.Item name='gamepad'>
<Icon name='gamepad' />
Games
</Menu.Item>
<Menu.Item name='camera'>
<Icon name='camera' />
Channels
</Menu.Item>
</Sidebar>
<Sidebar.Pusher>
<Segment basic>
<Header as='h3'>Application Content</Header>
<Image src='/assets/images/wireframe/paragraph.png' />
</Segment>
</Sidebar.Pusher>
</Sidebar.Pushable>
</div>
)
}
}
export default SidebarLeftScaleDown
然后我像这样从另一个类中调用它:
<SidebarLeftScaleDown/>
但我不断收到此错误:
[INFO] Module build failed: SyntaxError: C:/Users/611727594/Desktop/OverchargeSpringProject/src/main/js/sidebarLeftScaleDown.js: Unexpected token (6:12)
[INFO]
[INFO] 4 | class SidebarLeftScaleDown extends Component {
[INFO] 5 |
[INFO] > 6 | state = { visible: false }
[INFO] | ^
[INFO] 7 |
[INFO] 8 | toggleVisibility = () => this.setState({ visible: !this.state.visible })
[INFO] 9 |
【问题讨论】:
标签: reactjs semantic-ui semantic-ui-react