Vue+Router+Element實(shí)現(xiàn)簡(jiǎn)易導(dǎo)航欄
本項(xiàng)目為大家分享了Vue+Router+Element實(shí)現(xiàn)簡(jiǎn)易導(dǎo)航欄的具體代碼,供大家參考,具體內(nèi)容如下
項(xiàng)目結(jié)構(gòu):
直接上代碼:主要就是引入配置路由Router
①:引入Router(路由管理器)
//config.js 頁(yè)面 //導(dǎo)航欄 import Home from '../components/home' //首頁(yè) import Index from '../components/index' //視頻平臺(tái) import Vid from '../components/vid_terrace' //其他頁(yè)面 import Rests from '../components/rests' export default { routes:[ { path:'/home', name: 'home', component: Home, }, { /** * home 配置的就是導(dǎo)航欄,這個(gè)必須配置不然就會(huì)跳轉(zhuǎn)到新的頁(yè)面 * /home/index */ path: '/home', name: 'home', component: Home, redirect: 'index', children: [ { name: 'index', path: '/index', component: Index }, { name: 'vid', path: '/vid', component: Vid }, { name:'rests', path: '/rests', component: Rests } ] } ], // 去掉Vue地址的# mode:'history' }
//index.js 頁(yè)面
import VueRouter from "vue-router"; import Vue from "vue"; import Config from './config'; Vue.use(VueRouter); let router = new VueRouter(Config); export default router;
//main.js 頁(yè)面
import Vue from 'vue'; import App from './App'; // 引入Element-ui import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; //引入./router/index文件 import router from "./router/index"; Vue.config.productionTip = false Vue.use(ElementUI); new Vue({ el: '#app', render: h => h(App), router })
//app.vue 頁(yè)面
<template> <div id="app"> <!-- 組件是一個(gè) functional 組件,渲染路徑匹配到的視圖組件。--> <router-view></router-view> </div> </template> <script> export default { name: 'App', components: { } } </script> <style> #app { text-align: center; color: #2c3e50; margin-top: 60px; } </style>
//home.vue 頁(yè)面
<template> <!-- 導(dǎo)航欄--> <div> <el-menu :default-active="this.$route.path" class="el-menu-demo" mode="horizontal" @select="handleSelect" router background-color="#545c64" text-color="#fff" active-text-color="#ffd04b"> <el-menu-item v-for="(tit,i) in titleList" :key="i" :index="tit.name"> <template>{{ tit.navItem }}</template> </el-menu-item> </el-menu> <el-main class="detailed-content"> <router-view /> </el-main> </div> </template> <script> export default { data() { return { activeIndex: '1', activeIndex2: '1', titleList:[ {name:'index', navItem:'首頁(yè)'}, {name:'vid',navItem:'視頻平臺(tái)'}, {name:'rests',navItem:'其他'}, ] } }, methods: { handleSelect(key, keyPath) { console.log(key, keyPath); } } } </script> <style scoped> </style>
效果圖:
乍一看可能有點(diǎn)繁瑣,因?yàn)镽outer的配置有點(diǎn)亂,其實(shí)導(dǎo)航欄的代碼沒(méi)幾行,如果你的環(huán)境已經(jīng)搭好那就只需要看下home.vue和config.js文件就好。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3+axios+Mock.js實(shí)現(xiàn)登錄功能的示例代碼
本文主要介紹了Vue3+axios+Mock.js實(shí)現(xiàn)登錄功能的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05sublime如何配置開(kāi)發(fā)VUE環(huán)境自動(dòng)格式化代碼
這篇文章主要介紹了sublime如何配置開(kāi)發(fā)VUE環(huán)境自動(dòng)格式化代碼問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03詳解如何使用vue-cli腳手架搭建Vue.js項(xiàng)目
這篇文章主要介紹了詳解如何使用vue-cli腳手架搭建Vue.js項(xiàng)目 ,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05vue項(xiàng)目中實(shí)現(xiàn)全局引入jquery
這篇文章主要介紹了vue項(xiàng)目中實(shí)現(xiàn)全局引入jquery方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06vue項(xiàng)目中引入vue-datepicker插件的詳解
這篇文章主要介紹了vue項(xiàng)目中引入vue-datepicker插件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05jenkins自動(dòng)構(gòu)建發(fā)布vue項(xiàng)目的方法步驟
這篇文章主要介紹了jenkins自動(dòng)構(gòu)建發(fā)布vue項(xiàng)目的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01