1. 程式人生 > 程式設計 >vue+element-ui實現頭部導航欄元件

vue+element-ui實現頭部導航欄元件

本文例項為大家分享了+element-ui實現頭部導航欄元件具體程式碼,供大家參考,具體內容如下

話不多說,先上一張效果圖:

vue+element-ui實現頭部導航欄元件

這是一個頭部導航欄,最常見的一個功能,滑鼠點選切換不同介面,樣式跟隨。
首先就是下載element-ui框架

npm installhttp://www.cppcns.com element-ui

在main.檔案裡面全域性引入這個ui框架

vue+element-ui實現頭部導航欄元件

然後就是在app.vue檔案裡面註冊這個top元件

vue+element-ui實現頭部導航欄元件

這是用vue和“餓了麼”來實現的頭部導航欄,看一下程式碼:

<template>
  <div class="header">
    <div class="img">
      <img src="@/assets/image/index/logo.png" alt="vue+element-ui實現頭部導航欄元件">
    </div>
    <el-menu
      :default-active="this.$route.path"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      router
      b
ackground-color="#fff" text-color="#333" active-text-color="#0084ff" style="flex:1" > <el-menu-item v-for="(item,i) in navList" :key="i" :index="item.name"> <template slot="title"> <span> {{ item.navItem }}</span> </template> </el-menu-item> </el-menu> </div> </template> <script> export default { data() { return { navList:[ {name:'/home',navItem:'首頁'},{name:'/home/classRoom',navItem:'我的班級'},{name:'/home/course',navItem:'我的課程'},{name:'/home/exam',navItem:'建立考試'},{name:'/home/practice',navItem:'建立練習'},] } },methodXSeSvf
s: { handleSelecthttp://www.cppcns.com(key,keyPath) { } } } </script> <style> .el-menu-item{ font-size: 18px !important; } .el-menu-item.is-active { color: #ea5b2c !important; font-size: 18px !important; } .el-menu--horizontal>.el-menu-item.is-active { border-bottom: 2px solid #ea5b2c !important; } </style> <style lang="s" scoped> .header { display: flex; width: 100%; .img { background: #ffffff; border-bottom: solid 1px #e6e6e6; img { height:50px; padding:10px; } } } </style>

能力有限,寫的不好的地方還望路過的大佬指點一二。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。