一、NavMenu重要標(biāo)簽和參數(shù)說明
-
mode:導(dǎo)航欄的模式,默認(rèn)值vertical 導(dǎo)航欄處于垂直狀態(tài),改為horizonta可變?yōu)樗侥J健?/p>
-
index:唯一標(biāo)志。
-
default-active:激活當(dāng)前菜單的index。
-
router: 是否使用路由,啟用后可以通過index作為地址進(jìn)行跳轉(zhuǎn)。
-
<el-menu-item index="1">導(dǎo)航欄中的子菜單標(biāo)簽。
-
<el-submenu> 生成二級(jí)菜單。
代碼實(shí)現(xiàn):
<template>
<el-menu
:default-active="path"
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
text-color="black"
background-color="white"
active-text-color="#31c27c"
router
>
<el-menu-item index="1">一</el-menu-item>
<el-menu-item index="2">二</el-menu-item>
<el-menu-item index="3">三</el-menu-item>
<!-- 添加二級(jí)菜單 -->
<el-submenu index="4">
<template slot="title">四</template>
<el-menu-item index="4-1">4.1</el-menu-item>
<el-menu-item index="4-2">4.2</el-menu-item>
<el-menu-item index="4-3">4.3</el-menu-item>
</el-submenu>
</el-menu>
</template>
二、導(dǎo)航菜單中的router用法
router默認(rèn)值為false需要激活來啟用。
<el-menu router="true"></el-menu>
其中,index的值作為地址進(jìn)行跳轉(zhuǎn)。
案例:
<template>
<div>
<el-menu
:default-active="path"
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
text-color="black"
background-color="white"
active-text-color="#31c27c"
router
>
<el-menu-item>
<img
src=""
alt=""
/>
</el-menu-item>
<!-- 使用v-for循環(huán)添加子菜單 -->
<template v-for="(item, index) in nav_menu_data">
<el-menu-item :index="item.path" :key="index">
{{ item.title }}
</el-menu-item>
</template>
<!-- 登錄與退出按鈕 -->
<!-- 從服務(wù)端搜索數(shù)據(jù) -->
<el-autocomplete
v-model="state"
:fetch-suggestions="querySearchAsync"
placeholder="搜索音樂、歌單、MV"
@select="handleSelect"
class="search"
suffix-icon="el-icon-search"
></el-autocomplete>
<el-button type="text" class="btn_login">登錄</el-button>
</el-menu>
</div>
</template>
<script>
export default {
name: "NavMenu",
data() {
return {
path: "",
nav_menu_data: [
{
title: "發(fā)現(xiàn)音樂",
path: "/home/faxian",
},
{
title: "我的音樂",
path: "/Menu/Page2",
},
{
title: "關(guān)注",
path: "/home/guanzhu",
},
{
title: "分類",
path: "/Menu/Page4",
},
],
activeIndex: "1",
};
},
created() {
this.onRouteChanged();
},
watch: {
$route: "onRouteChanged",
},
methods: {
onRouteChanged() {
let that = this;
that.path = that.$route.path;
},
handleSelect(key, keyPath) {
console.log(key, keyPath);
},
},
};
</script>
<style lang="less" scoped>
</style>
效果圖:文章來源:http://www.zghlxwxcb.cn/news/detail-632475.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-632475.html
到了這里,關(guān)于Element -Ui之NavMenu導(dǎo)航欄的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!