在后臺管理系統(tǒng)中當(dāng)點(diǎn)擊某一按鈕時,頁面發(fā)生跳轉(zhuǎn)(路由發(fā)生跳轉(zhuǎn),跳轉(zhuǎn)到與按鈕對應(yīng)的頁面),在跳轉(zhuǎn)的同時在側(cè)邊欄中打開與之對應(yīng)模塊的菜單項(xiàng)
1.點(diǎn)擊按鈕跳轉(zhuǎn)到/pay/PayIndex頁面
2.在后臺管理系統(tǒng)中側(cè)邊欄使用的是element ui 中的NavMenu導(dǎo)航菜單組件,在后臺管理系統(tǒng) src/layout/components/Sidebar/index中代碼如下:
<template>
<div
:class="{ 'has-logo': showLogo }"
:style="{
backgroundColor:settings.sideTheme === 'theme-dark'? variables.menuBackground : variables.menuLightBackground,}">
<logo v-if="showLogo" :collapse="isCollapse" />
<el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper">
<el-menu
:default-active="activeMenu"
:collapse="isCollapse"
:background-color=" settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground"
:text-color="settings.sideTheme === 'theme-dark' ? variables.menuColor: variables.menuLightColor"
:unique-opened="true"
:active-text-color="settings.theme"
:collapse-transition="false"
mode="vertical"
:default-openeds="openeds"
>
<sidebar-item
v-for="(route, index) in sidebarRouters"
:key="route.path + index"
:item="route"
:base-path="route.path"
/>
</el-menu>
<!-- :index="route.path" -->
</el-scrollbar>
</div>
</template>
<script>
import { mapGetters, mapState } from "vuex";
import Logo from "./Logo";
import SidebarItem from "./SidebarItem";
import variables from "@/assets/styles/variables.scss";
export default {
components: { SidebarItem, Logo },
data() {
return {
openeds: [],
};
},
computed: {
...mapState(["settings"]),
...mapGetters(["sidebarRouters", "sidebar"]),
activeMenu() {
const route = this.$route;
const { meta, path } = route;
// if set path, the sidebar will highlight the path you set
if (meta.activeMenu) {
return meta.activeMenu;
}
return path;
},
showLogo() {
return this.$store.state.settings.sidebarLogo;
},
variables() {
return variables;
},
isCollapse() {
return !this.sidebar.opened;
},
},
//組件路由發(fā)生變化,打開與組件對應(yīng)模塊的菜單項(xiàng)
watch: {
"$route.path": function (newVal) {
// 先清空數(shù)組,確保數(shù)組中只存放一個路由信息
if (this.openeds.length > 0) {
this.openeds = [];
}
// newVal為路由 /pay/PayIndex
let str = newVal.split("/");
// url為/pay 打開/pay所對應(yīng)的菜單項(xiàng)
let url = "/" + str[1];
this.openeds.push(url);
},
},
};
</script>
可通過default-openeds指定想要打開的菜單項(xiàng)(也可設(shè)置默認(rèn)打開的菜單項(xiàng) 如?:default-openeds="[/system/user]")?
?
?通過監(jiān)聽路由的變化,打開與要跳轉(zhuǎn)的組件頁面相對應(yīng)的菜單項(xiàng),把變化的路由存放到openeds數(shù)組中,實(shí)現(xiàn)路由跳轉(zhuǎn)動態(tài)的打開與之對應(yīng)的菜單項(xiàng)
文章來源:http://www.zghlxwxcb.cn/news/detail-619581.html
以上就是實(shí)現(xiàn)路由跳轉(zhuǎn)打開對應(yīng)模塊菜單項(xiàng)的所有步驟啦文章來源地址http://www.zghlxwxcb.cn/news/detail-619581.html
到了這里,關(guān)于若依vue框架+element ui 組件路由跳轉(zhuǎn)與菜單聯(lián)動的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!