antdesignvue导航菜单与路由配置操作此功能包含:
1.根据动态路由⾃动展开与⾃动选择对应路由所在页⾯菜单
2.只展开⼀个⼦菜单
3.兄弟组件控制菜单与路由
<a-menu
:openKeys="openKeys"
:selectedKeys="selectedKeys"
mode="inline"
theme="dark"
:inlineCollapsed="$store.state.isCollapse"
@click='select'
@openChange='openChange'
>
<a-sub-menu v-for="item in menu" :key="item.name" :index="item.title">
<span slot="title"
><a-icon :type="item.icon" /><span>{{ item.title }}</span></span
>
<a-menu-item
v-for="subItem in item.submenu"
:key="subItem.index"
:index="subItem.index"
>
<router-link :to="subItem.path">
{{ }}
</router-link>
</a-menu-item>
</a-sub-menu>
</a-menu>
菜单栏路由配置:
{导航菜单
title: 'Dashboard',
name: '/dashboard',
icon: 'dashboard',
submenu: [
{ text: '分析页', path: '/dashboard/analysis', index: '/analysis' },
{ text: '监控页', path: '/dashboard/monitor', index: '/monitor' }
]
}
默认开启的⼦菜单及选中项配置
openKeys: [this.$route.path.substr(0, this.$route.path.lastIndexOf('/'))],
selectedKeys: [this.$route.path.substr(this.$route.path.lastIndexOf('/'))],
rootSubmenuKeys: ['/dashboard', '/form', '/table', '/user'], // 有⼏个⼦菜单项就贴⼏个
功能代码:
methods: {
openChange (openKeys) { // 只展开⼀个⼦菜单
const latestOpenKey = openKeys.find(key => this.openKeys.indexOf(key) === -1)
if (SubmenuKeys.indexOf(latestOpenKey) === -1) {
this.openKeys = openKeys
} else {
this.openKeys = latestOpenKey ? [latestOpenKey] : []
}
},
select ({ item, key, selectedKeys }) { // 选中项
this.selectedKeys = [key]
}
},
created () {
this.$bus.$on('goperson', (url) => { // 组件间通信设置菜单栏状态此处功能可查看另⼀篇博客
this.openKeys = [ url.substr(0, url.lastIndexOf('/')) ]
this.selectedKeys = [ url.substr(url.lastIndexOf('/')) ]
})
}
补充知识:Ant Design Pro 侧边菜单栏 + 路由Router
1、⾸先到 menu.js
{
name: '新添加的表单',
path: 'new-basic-form',
},
添加从30⾏-33⾏代码,然后在你的侧边栏就是多出来⼀个 “新添加的表单”
但是当你点击的时候,你会发现右边 Main 是404,因为我们还需要配置⼀下router (代表当我点击“新添加的表单”这个彩蛋的时候,右边需要显⽰的页⾯是什么)
2、点击router.JS 在表单页下⾯ children 添加30⾏-44⾏
'/form/new-basic-form': {
component: dynamicWrapper(app, ['form'], () => import('../routes/Forms/newBasicForm')), },
因为链接的是newBasicForm 就需要创建⼀个newBasicForm.JS
在routes——》Forms——》下创建newBasicForm.js
newBasicForm.js⾥⾯的代码为:
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import {
Form,
Input,
DatePicker,
Select,
Button,
Card,
InputNumber,
Radio,
Icon,
Checkbox,
Tooltip,
} from 'antd';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
import styles from './style.less';
const FormItem = Form.Item;
@ate()
export default class newBasicForms extends PureComponent {
handleSubmit = e => {
e.preventDefault();
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
this.props.dispatch({
type: 'form/submitRegularForm',
payload: values,
});
}
});
};
render() {
const { getFieldDecorator, getFieldValue } = this.props.form;
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 7 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 12 },
md: { span: 10 },
},
};
return (
//  这个个组件⾃带头
<PageHeaderLayout
title="new-基础表单"
content="表单页⽤于向⽤户收集或验证信息,基础表单常见于数据项较少的表单场景。"    >
<Card bordered={false}>
<p>你好我叫刘国富</p>
<Form onSubmit={this.handleSubmit} hideRequiredMark style={{ marginTop: 8 }}>
<FormItem {...formItemLayout} label="标题">
{getFieldDecorator('title', {
rules: [
{
required: true,
message: '请输⼊标题',
},
],
})(<Input placeholder="给⽬标起个名字" />)}
</FormItem>
</Form>
</Card>
</PageHeaderLayout>
);
}
}
当点击新添加的表单,右边则显⽰为:你好我叫刘国富。
以上这篇ant design vue导航菜单与路由配置操作就是⼩编分享给⼤家的全部内容了,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。