最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

element-plus默認菜單打開步驟

 更新時間:2024年08月23日 09:58:30   作者:庫庫林_沙琪馬  
在 Vue 3 中使用 Element Plus 的 <el-menu> 組件時,默認情況下菜單項是關閉狀態(tài)的,如果你想讓某個菜單項默認處于展開狀態(tài),你可以通過設置菜單項的 default-active 屬性來實現(xiàn),這篇文章主要介紹了element-plus默認菜單打開,需要的朋友可以參考下

在 Vue 3 中使用 Element Plus 的 <el-menu> 組件時,默認情況下菜單項是關閉狀態(tài)的。如果你想讓某個菜單項默認處于展開狀態(tài),你可以通過設置菜單項的 default-active 屬性來實現(xiàn)。

默認寫法

步驟 1: 設置 default-active

你需要在 <el-menu> 組件上設置 default-active 屬性,并為其提供一個值,該值應該是你希望默認激活的菜單項的索引或路徑。

示例代碼

假設你有一個簡單的菜單結構,其中包含一個子菜單,你想讓這個子菜單默認展開:

<template>
  <el-menu :default-active="activeIndex" class="el-menu-vertical-demo">
    <el-sub-menu index="1">
      <template #title>
        <el-icon><location /></el-icon>
        <span>導航一</span>
      </template>
      <el-menu-item index="1-1">選項1</el-menu-item>
      <el-menu-item index="1-2">選項2</el-menu-item>
      <el-menu-item index="1-3">選項3</el-menu-item>
    </el-sub-menu>
    <el-menu-item index="2">
      <el-icon><document /></el-icon>
      <template #title>導航二</template>
    </el-menu-item>
    <el-menu-item index="3" disabled>
      <el-icon><setting /></el-icon>
      <template #title>導航三</template>
    </el-menu-item>
  </el-menu>
</template>
<script setup>
import { ref } from 'vue';
import { Location, Document, Setting } from '@element-plus/icons-vue';
const activeIndex = ref('1-1');  // 默認激活 "1-1" 菜單項
</script>

說明

  • default-active 屬性:設置為 '1-1',表示默認激活 index="1-1" 的菜單項。
  • el-sub-menu:用于創(chuàng)建子菜單。
  • el-menu-item:用于創(chuàng)建菜單項。
  • <el-icon>:用于顯示圖標。
  • <template #title>:用于自定義菜單項的標題。

注意事項

  • 如果你想讓一個子菜單默認展開,可以將 default-active 設置為該子菜單中的任意一個子菜單項的 index。
  • 如果你想讓多個子菜單默認展開,可以使用數(shù)組形式的 default-active 屬性。

示例:多個子菜單默認展開

如果你想讓多個子菜單默認展開,你可以將 default-active 設置為一個數(shù)組,包含你希望默認激活的菜單項的索引。

<template>
  <el-menu :default-active="['1-1', '2']" class="el-menu-vertical-demo">
    <el-sub-menu index="1">
      <template #title>
        <el-icon><location /></el-icon>
        <span>導航一</span>
      </template>
      <el-menu-item index="1-1">選項1</el-menu-item>
      <el-menu-item index="1-2">選項2</el-menu-item>
      <el-menu-item index="1-3">選項3</el-menu-item>
    </el-sub-menu>
    <el-menu-item index="2">
      <el-icon><document /></el-icon>
      <template #title>導航二</template>
    </el-menu-item>
    <el-menu-item index="3" disabled>
      <el-icon><setting /></el-icon>
      <template #title>導航三</template>
    </el-menu-item>
  </el-menu>
</template>
<script setup>
import { ref } from 'vue';
import { Location, Document, Setting } from '@element-plus/icons-vue';
const activeIndex = ref(['1-1', '2']);  // 默認激活 "1-1" 和 "2" 菜單項
</script>

在這個例子中,default-active 設置為 ['1-1', '2'],表示默認激活 index="1-1"index="2" 的菜單項。這將使得 index="1" 的子菜單及其第一個子菜單項 index="1-1" 處于展開狀態(tài),并且 index="2" 的菜單項也處于激活狀態(tài)。

特殊寫法

Menu 組件

<template>
    <template v-for="(item, index) in menuList" :key="index">
        <!-- 沒有子路由 -->
        <template v-if="!item.children">
            <el-menu-item v-if="!item.meta.hidden" :index="item.path" @click="goRoute">
                <el-icon>
                    <component :is="item.meta.icon"></component>
                </el-icon>
                <template #title>
                    <span>{{ item.meta.title }}</span>
                </template>
            </el-menu-item>
        </template>
        <!-- 只有一個子路由 -->
        <template v-if="item.children && item.children.length == 1">
            <el-menu-item v-if="!item.children[0].meta.hidden" :index="item.children[0].path" @click="goRoute">
                <el-icon>
                    <component :is="item.children[0].meta.icon"></component>
                </el-icon>
                <template #title>
                    <span>{{ item.children[0].meta.title }}</span>
                </template>
            </el-menu-item>
        </template>
        <!-- 有多個子路由 -->
        <el-sub-menu v-if="item.children && item.children.length > 1" :index="item.path">
            <template #title>
                <el-icon>
                    <component :is="item.meta.icon"></component>
                </el-icon>
                <span>{{ item.meta.title }}</span>
            </template>
            <Menu :menuList="item.children"></Menu>
        </el-sub-menu>
    </template>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router'
// 引入路由器
const $router = useRouter()
// 獲取父組件傳遞的數(shù)據(jù)
defineProps(['menuList'])
// 點擊菜單的回調
const goRoute = (vc: any) => {
    // 路由跳轉
    $router.push(vc.index)
}
</script>
<script lang="ts">
export default {
    name: 'Menu'
}
</script>
<style scoped></style>

菜單欄 組件:

<template>
    <div class="layout_container">
        <!-- 左側菜單 -->
        <div class="layout_slider">
            <Logo></Logo>
            <!-- 展示菜單 -->
            <!-- 滾動組件 -->
            <el-scrollbar class="scrollbar">
                <!-- 菜單組件 -->
                <el-menu background-color="#2e2e2e" text-color="white" active-text-color="yellowgreen" :default-active="$route.path">
                    <Menu :menuList="userStore.menuRoutes"></Menu>
                </el-menu>
            </el-scrollbar>
        </div>
        <!-- 頂部導航 -->
        <div class="layout_tabbar">456</div>
        <!-- 內(nèi)容展示區(qū)域 -->
        <div class="layout_main">
            <Main></Main>
        </div>
    </div>
</template>
<script setup lang="ts">
// 引入左側菜單logo子組件
import Logo from './logo/index.vue'
// 引入菜單組件
import Menu from './menu/index.vue'
// 右側內(nèi)容的展示區(qū)
import Main from './main/index.vue'
// 獲取路由對象
import { useRoute } from 'vue-router';
// 獲取用戶相關的小倉庫
import useUserStore from '@/store/modules/user';
let userStore = useUserStore();
// 獲取路由對象
let $route = useRoute();
</script>
<style scoped lang="scss">
.layout_container {
    width: 100%;
    height: 100vh;
    background-color: red;
    .layout_slider {
        width: $base-menu-width;
        height: 100vh;
        background-color: $base-menu-bg;
        .scrollbar {
            width: $base-menu-width;
            height: calc(100vh - $base-menu-logo-height);
            .el-menu {
                border-right: none;
            }
        }
    }
    .layout_tabbar {
        position: fixed;
        width: calc(100% - $base-menu-width);
        height: $base-tabbar-height;
        background-color: cyan;
        top: 0px;
        left: $base-menu-width;
    }
    .layout_main {
        position: fixed;
        width: calc(100% - $base-menu-width);
        height: calc(100% - $base-tabbar-height);
        background-color: yellow;
        top: $base-tabbar-height;
        left: $base-menu-width;
        padding: 20px;
        overflow: auto;
    }
}
</style>

到此這篇關于element-plus默認菜單打開的文章就介紹到這了,更多相關element-plus菜單打開內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

乡城县| 梅河口市| 东源县| 屯门区| 银川市| 东明县| 霍州市| 定州市| 静海县| 长治县| 北安市| 岢岚县| 上思县| 滨州市| 拉萨市| 綦江县| 天水市| 祁门县| 鲜城| 湛江市| 通渭县| 拜城县| 综艺| 克拉玛依市| 七台河市| 阜南县| 安平县| 宾阳县| 蕲春县| 和平区| 荥阳市| 新郑市| 乌鲁木齐市| 青神县| 云安县| 湛江市| 枞阳县| 宁城县| 东莞市| 孟津县| 周宁县|