Element-ui之導航菜單

0. 總結

1. 菜單 <el-menu> 包裹子菜單 <el-submenu>
2. 顯示出來的層級關係由 index 的值控制:1 1-1 1-1-1 分別爲三層
複製代碼

1. 安裝並使用 element-ui

安裝

npm i element-ui
複製代碼

使用

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI);
複製代碼

2. 頂部導航

<!-- default-active: 當前激活的菜單 index mode: 默認 mode 爲 vertical,更改成 horizontal 爲水平菜單 background-color: 菜單背景色 text-color: 菜單文字色 active-text-color: 激活的菜單文字顏色 -->
<el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
  <el-menu-item index="1">處理中心</el-menu-item>
  <el-submenu index="2">
    <template slot="title">個人工做臺</template>
    <el-menu-item index="2-1">選項1</el-menu-item>
    <el-menu-item index="2-2">選項2</el-menu-item>
    <el-menu-item index="2-3">選項3</el-menu-item>
    <el-submenu index="2-4">
      <template slot="title">選項4</template>
      <el-menu-item index="2-4-1">選項1</el-menu-item>
      <el-menu-item index="2-4-2">選項2</el-menu-item>
      <el-menu-item index="2-4-3">選項3</el-menu-item>
    </el-submenu>
  </el-submenu>
  <el-menu-item index="3" disabled>消息中心</el-menu-item>
  <el-menu-item index="4"><a href="https://www.baidu.com" target="blank">百度</a></el-menu-item>
</el-menu>
複製代碼
data(){
    return {
      activeIndex: '1',
      activeIndex2: '1'
    }
  }
複製代碼

3. 側邊欄

<template>
  <div class="home">
    <!-- 側邊欄 -->
    <el-menu default-active="2" background-color="#545c64" active-text-color="#ffd04b" text-color="#fff" @open="handleOpen" @close="handleClose" >
      <!-- el-submenu: 子菜單 index: key: 1 Path: ["1"] -->
      <el-submenu index="1">
        <!-- slot="title" 菜單欄 -->
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>導航一</span>
        </template>
        <!-- 分組 -->
        <el-menu-item-group>
          <template slot="title">分組一</template>
          <el-menu-item index="1-1">選項1</el-menu-item>
          <el-menu-item index="1-2">選項2</el-menu-item>
        </el-menu-item-group>
        <el-menu-item-group title="分組2">
          <el-menu-item index="1-3">選項3</el-menu-item>
        </el-menu-item-group>
        <el-submenu index="1-4">
          <template slot="title">選項4</template>
          <el-menu-item index="1-4-1">選項1</el-menu-item>
        </el-submenu>
      </el-submenu>
      <el-menu-item index="2">
        <i class="el-icon-menu"></i>
        <span slot="title">導航二</span>
      </el-menu-item>
      <el-menu-item index="3" disabled="">
        <i class="el-icon-document"></i>
        <span>導航三</span>
      </el-menu-item>
      <el-menu-item index="3">
        <i class="el-icon-setting"></i>
        <span slot="title">導航四</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script> // @ is an alias to /src export default { name: 'home', components: { }, methods: { handleOpen(key, keyPath) { console.log(key, keyPath); }, handleClose(key, keyPath) { console.log(key, keyPath); } } } </script>
複製代碼

具體參考官方文檔javascript

相關文章
相關標籤/搜索