Vue 實現左邊導航欄且右邊顯示具體內容(element-ui)

最終效果圖:

 

 

如今開始進入正題:css

一、安裝element-uihtml

npm i element-ui -S

 

CDN

目前能夠經過 unpkg.com/element-ui 獲取到最新版本的資源,在頁面上引入 js 和 css 文件便可開始使用。npm

<!-- 引入樣式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入組件庫 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

2.在main.js中引入element-ui

 

三、在 components 中新建導航欄組件ui

<template>
  <el-row class="tac">
    <el-col :span="12">
      <h5>默認顏色</h5>
      <el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
      >
        <el-submenu index="1">
          <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="/demo" @click="goTo('/demo')">
          <i class="el-icon-menu"></i>
          <span slot="title">導航二</span>
        </el-menu-item>
        <el-menu-item index="/index" @click="goTo('/index')">
          <i class="el-icon-setting"></i>
          <span slot="title">導航三</span>
        </el-menu-item>
      </el-menu>
    </el-col>
    <router-view></router-view>
  </el-row>
</template>

<script> export default { data() { return {}; }, methods: { handleOpen(key, keyPath) { console.log(key, keyPath); }, handleClose(key, keyPath) { console.log(key, keyPath); }, goTo(path) { this.$router.replace(path); } } }; </script>

<style scoped> .el-col-12{ width: 15%; } </style>

 

四、在router下的index.js中引入組件,搭配路由this

 

五、添加跳轉路徑url

   

 

 

六、很重要的一點,加上路由出口,也就是右側顯示部分spa

 

這樣就實現成功啦.net

相關文章
相關標籤/搜索