TabBar标签栏
import React from "react";
// 1.在pages文件中创建News/indexed.js组件
// 2.在home组件中添加一个Route作为子路由(嵌套的路由)的出口
// 3.设置嵌套路由的path,格式以父组件路由path开头(父组件展示,子组件才会展示)
//导入路由
import { Route } from "react-router";
//导入tabbar
import { TabBar } from 'antd-mobile';
//导入news组件
import News from "../News";
export default class Home extends React.Component{
const tabs = [
{
key: 'home',
title: '首页',
icon: <AppOutline />,
badge: Badge.dot,
},
{
key: 'todo',
title: '我的待办',
icon: <UnorderedListOutline />,
badge: '5',
},
{
key: 'message',
title: '我的消息',
icon: (active: boolean) =>
active ? <MessageFill /> : <MessageOutline />,
badge: '99+',
},
{
key: 'personalCenter',
title: '个人中心',
icon: <UserOutline />,
},
]
render(){
return (
<div style={{backgroundColor:'skyblue',padding:10}}>
首页
{/* 渲染子路由 */}
<Route path="/home/news" component={News}></Route>
<TabBar>
{tabs.map(item => (
<TabBar.Item
key={item.key}
icon={item.icon}
title={item.title}
badge={item.badge}
/>
))}
</TabBar>
</div>
)
}
}
引用以后报错
index.js:1 ./src/pages/Home/index.js
SyntaxError: E:\资料\html\html\reacrt-basic\hkzf-mobile\src\pages\Home\index.js: Unexpected token (17:11)
15 |
16 | export default class Home extends React.Component{
> 17 | const tabs = [
| ^
18 | {
19 | key: 'home',
20 | title: '首页',
console.<computed> @ index.js:1
handleErrors @ webpackHotDevClient.js:174
push../node_modules/react-dev-utils/webpackHotDevClient.js.connection.onmessage @ webpackHotDevClient.js:213
index.js:1 src\pages\Home\index.js
Line 17:12: Parsing error: Unexpected token
15 |
16 | export default class Home extends React.Component{
> 17 | const tabs = [
| ^
18 | {
19 | key: 'home',
20 | title: '首页',