vue使用vuex實(shí)現(xiàn)首頁(yè)導(dǎo)航切換不同路由的方法
vue實(shí)現(xiàn)首頁(yè)導(dǎo)航切換不同路由的方式(二)【使用vuex實(shí)現(xiàn)的】,具體代碼如下所示:
<nav> <!-- 導(dǎo)航欄 --> <div class="indexNavOut"> <div class="indexNav"> <ul class="navLi"> <li @click="checkNav()" style="width: 130px;"><router-link to="/home">了解海華教育(視頻)</router-link><!--<a href="#">了解海華教育(視頻)</a>--></li> <li @click="checkNav()" v-bind:class="{'active':Index=='#/home','active2':Index=='#/'}"> <router-link to="/home">首頁(yè)</router-link> </li> <li @click="checkNav()" v-bind:class="{'active':Index=='#/synopsis'}"><router-link to="/synopsis">學(xué)校簡(jiǎn)介</router-link> </li> <li @click="checkNav()" v-bind:class="{'active':Index=='#/major'}"><router-link to="/major">專業(yè)介紹</router-link> </li> <li @click="checkNav()" v-bind:class="{'active':Index=='#/campus'}"><router-link to="/campus">校園風(fēng)采</router-link> </li> <li @click="checkNav()" v-bind:class="{'active':Index=='#/news'}"><router-link to="/news">新聞資訊</router-link> </li> <li @click="checkNav()" v-bind:class="{'active':Index=='#/enrollment'}"><router-link to="/enrollment">招生信息</router-link> </li> <li @click="checkNav()" v-bind:class="{'active':Index=='#/employment'}"><router-link to="/employment">就業(yè)中心</router-link> </li> <li @click="checkNav()" v-bind:class="{'active':Index=='#/enlist'}"><router-link to="/enlist">在線報(bào)名</router-link> </li> <li @click="checkNav()" v-bind:class="{'active':Index=='#/contact'}"><router-link to="/contact">聯(lián)系我們</router-link> </li> </ul> </div> </div> </nav>
css:
/* 導(dǎo)航欄 */ .indexNavOut{ background-color: #486B8A; height: 60px; } .indexNav{ width: 80%; margin: 0 auto; } .navLi{ display: flex; } .navLi li:nth-child(1){ flex: 1.8; } .navLi li{ flex: 1; } .navLi li a{ text-decoration: none; color: #fff; font-size: 16px; padding-bottom: 17px; } .indexNav .icon{ width: 230px; margin-top: 10px; } .indexNav .icon img{ width: 100%; } .navLi li { height: 60px; line-height: 60px; position: relative; } .navLi li.active a{ border-bottom: 3px solid #E96463; } .navLi li.active2 a{ border-bottom: 3px solid #E96463; } .navLi li:last-child:after{ border-right: none; } .navLi li .line{ width: 20px; height: 3px; background: #E96463; border: none; position: absolute; /*top: -14px;*/ /*right: -32px;*/ left: 50px; top: 45px; z-index: 100; }
js:
main.js代碼:
import Vuex from 'vuex' Vue.use(Vuex); const store = new Vuex.Store({ state: { majorDetail: false, Index: document.location.hash,//導(dǎo)航條跳轉(zhuǎn)路由樣式控制 }, mutations: { //控制專業(yè)介紹詳情顯示隱藏 updatemajorDetail(state, majorDetail) { state.majorDetail = majorDetail; }, updateIndex(state, Index) { state.Index = Index; } } });
效果圖:
現(xiàn)在在這個(gè)頁(yè)面里點(diǎn)擊了解更多的時(shí)候跳轉(zhuǎn)到新聞資訊頁(yè)面,然后然后state里的值,然后改變當(dāng)前的url以及導(dǎo)航選中新聞資訊。
總結(jié)
以上所述是小編給大家介紹的vue使用vuex實(shí)現(xiàn)首頁(yè)導(dǎo)航切換不同路由的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
稍微學(xué)一下Vue的數(shù)據(jù)響應(yīng)式(Vue2及Vue3區(qū)別)
這篇文章主要介紹了稍微學(xué)一下 Vue 的數(shù)據(jù)響應(yīng)式(Vue2 及 Vue3),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11簡(jiǎn)單實(shí)現(xiàn)vue中的依賴收集與響應(yīng)的方法
這篇文章主要介紹了簡(jiǎn)單實(shí)現(xiàn)vue中的依賴收集與響應(yīng)的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-02-02Vue3?vite配置css?的sourceMap及文件引用配置別名的過(guò)程
這篇文章主要介紹了Vue3 vite配置css的sourceMap,及文件引用配置別名的過(guò)程,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07vue中PC端使用高德地圖實(shí)現(xiàn)搜索定位、地址標(biāo)記、彈窗顯示定位詳情(完整實(shí)例)
這篇文章主要介紹了vue中PC端使用高德地圖實(shí)現(xiàn)搜索定位、地址標(biāo)記、彈窗顯示定位詳情,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07詳解關(guān)于Vuex的action傳入多個(gè)參數(shù)的問(wèn)題
這篇文章主要介紹了詳解關(guān)于Vuex的action傳入多個(gè)參數(shù)的問(wèn)題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-02-02