亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue.js使用Element-ui實(shí)現(xiàn)導(dǎo)航菜單

 更新時(shí)間:2021年09月27日 17:29:54   作者:化而為鳥  
這篇文章主要為大家詳細(xì)介紹了vue.js使用Element-ui中實(shí)現(xiàn)導(dǎo)航菜單,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue.js使用Element-ui中實(shí)現(xiàn)導(dǎo)航菜單的具體代碼,供大家參考,具體內(nèi)容如下

寫這個(gè)的原因是因?yàn)楫?dāng)時(shí)寫這個(gè)功能時(shí)候element只有效果,但是功能沒有實(shí)現(xiàn),當(dāng)時(shí)一頭霧水

先放圖吧

大體實(shí)現(xiàn)思路我先講一下不然下面代碼片段會(huì)看懵,圈出來的左右兩部分,左邊是element復(fù)制就可實(shí)現(xiàn),右邊是跳轉(zhuǎn)的子組件。

首先創(chuàng)建導(dǎo)航菜單的vue文件,但這個(gè)文件里面只是引入組件,里面使用Container布局容器實(shí)現(xiàn)左右兩部分,左邊el-aside標(biāo)簽中放入導(dǎo)航菜單的組件,右邊el-main標(biāo)簽中寫<router-view></router-view>實(shí)現(xiàn)路由跳轉(zhuǎn)即可

導(dǎo)航菜單文件我起名為Elnav.vue

<template>
    <div class="app">
        <el-container>
        <el-aside>
            <navmenu></navmenu>
        </el-aside>
        <el-main>
            <router-view></router-view>
        </el-main>
        </el-container>
    </div>
</template>
<script>
import navmenu from './navmenu'
export default {
    data() {
        return {
            
        }
    },
    components:{
        navmenu
    }
}
</script>
<style scoped>

</style>

里面主要引入navmenu組件(navmenu組件就是elemet中的樣式)

navmenu.vue中

注意設(shè)置 default-active="$route.path"以及組件跳轉(zhuǎn)(選項(xiàng)一/二)的index值

<template>
    <div>
        <el-row>
            <el-col>
                
                <el-menu
                    default-active="$route.path"
                    router
                    class="el-menu-vertical-demo"
                    @open="handleOpen"
                    @close="handleClose"
                >
                    <el-submenu index="1">
                        <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>導(dǎo)航一</span>
                        </template>
                        <el-menu-item-group>
                            <template slot="title">分組一</template>
                            <el-menu-item index="/Elnav/one">選項(xiàng)1</el-menu-item>
                            <el-menu-item index="/Elnav/two">選項(xiàng)2</el-menu-item>
                        </el-menu-item-group>
                        <el-menu-item-group title="分組2">
                            <el-menu-item index="1-3">選項(xiàng)3</el-menu-item>
                        </el-menu-item-group>
                        <el-submenu index="1-4">
                            <template slot="title">選項(xiàng)4</template>
                            <el-menu-item index="1-4-1">選項(xiàng)1</el-menu-item>
                        </el-submenu>
                    </el-submenu>
                </el-menu>
            </el-col>
        </el-row>
    </div>
</template>
<script>
export default {
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    }
  },
  mounted() {
    console.log(this.$route);
  }
};
</script>
<style>
</style>

接下來就是路由的配置

{
    path: "/Elnav",
    name: "Elnav",   
    component: () =>
      import("../components/Elnav.vue"),
      children:[
        {
          path: "/Elnav/one",
          name: "one",   
          component: () =>
            import("../components/one.vue")
        },
        {
          path: "/Elnav/two",
          name: "two",   
          component: () =>
            import("../components/two.vue")
        }
      ]
  }

至于右邊內(nèi)容的one.vue以及其他vue文件的內(nèi)容就自己寫即可

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論