vue+element-ui實現(xiàn)頭部導(dǎo)航欄組件
本文實例為大家分享了vue+element-ui實現(xiàn)頭部導(dǎo)航欄組件具體代碼,供大家參考,具體內(nèi)容如下
話不多說,先上一張效果圖:

這是一個頭部導(dǎo)航欄,網(wǎng)站最常見的一個功能,鼠標(biāo)點擊切換不同界面,樣式跟隨。
首先就是下載element-ui框架
npm install element-ui
在main.js文件里面全局引入這個ui框架

然后就是在app.vue文件里面注冊這個top組件

這是用vue和“餓了么”來實現(xiàn)的頭部導(dǎo)航欄,看一下代碼:
<template>
<div class="header">
<div class="img">
<img src="@/assets/image/index/logo.png" alt="">
</div>
<el-menu
:default-active="this.$route.path"
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
router
background-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:'創(chuàng)建考試'},
{name:'/home/practice',navItem:'創(chuàng)建練習(xí)'},
]
}
},
methods: {
handleSelect(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="scss" scoped>
.header {
display: flex;
width: 100%;
.img {
background: #ffffff;
border-bottom: solid 1px #e6e6e6;
img {
height:50px;
padding:10px;
}
}
}
</style>
能力有限,寫的不好的地方還望路過的大佬指點一二。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue動畫—通過鉤子函數(shù)實現(xiàn)半場動畫操作
這篇文章主要介紹了vue動畫—通過鉤子函數(shù)實現(xiàn)半場動畫操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08
如何解決elementUI打包上線后icon圖標(biāo)偶爾亂碼問題
文章描述了在使用若依框架開發(fā)過程中遇到的圖標(biāo)亂碼問題,通過分析發(fā)現(xiàn)是由于sass編譯器將Unicode編碼轉(zhuǎn)換為明文導(dǎo)致的,文章提供了四種處理方法:使用css-unicode-loader、升高sass版本、替換element-ui的樣式文件和更換打包壓縮方式2025-01-01
關(guān)于vue-property-decorator的基礎(chǔ)使用實踐
這篇文章主要介紹了關(guān)于vue-property-decorator的基礎(chǔ)使用實踐,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08

