首頁 >web前端 >js教程 >使用vue實作二級路由設定方法

使用vue實作二級路由設定方法

亚连
亚连原創
2018-06-06 15:54:465267瀏覽

下面我就為大家分享一篇vue二級路由設定方法,具有很好的參考價值,希望對大家有幫助。

專案當中使用vue的時候一定會用到路由,並且二級路由甚至三集路由的需求都是剛需,當然,多級路由的配置方法和二級的是一樣的,簡單講講二級路由的配置吧。

先把一級路由的結構準備好:

 <router-link to="/discover">
  <p @click="clickFind(&#39;发现&#39;)">
   <span class="icon-find"></span>
   <p>发现</p>
  </p>
  </router-link>
  <router-link to="/todayStudy">
  <p @click="clickStudy(&#39;今日学习&#39;)">
   <span class="icon-todayStudy"></span>
   <p>今日学习</p>
  </p>
  </router-link>
  <router-link to="/listenAnyWhere">
  <p @click="clickListen(&#39;随时听&#39;)">
   <span class="icon-listenAny"></span>
   <p>随时听</p>
  </p>
  </router-link>
  <router-link to="/bought">
  <p @click="clickBought(&#39;已购&#39;)">
   <span class="icon-areadyBy"></span>
   <p>已购</p>
  </p>
  </router-link>
  <router-link to="/mine">
  <p @click="clickMe">
   <span class="icon-me"></span>
   <p>我</p>
  </p>
  </router-link>
 </p>
 <router-view></router-view>

在main.js裡引入模組,並設定路由:

import discover from &#39;./components/discover/discover.vue&#39;; 
import todayStudy from &#39;./components/todayStudy/study.vue&#39;; 
import listen from &#39;./components/listenAnyWhere/listen.vue&#39;; 
import bought from &#39;./components/bought/bought.vue&#39;; 
import mine from &#39;./components/mine/mine.vue&#39;;
const routes = [ 
 { 
 path: &#39;/&#39;, 
 redirect: &#39;/discover&#39; 
 }, 
 { 
 path: &#39;/discover&#39;, 
 component: discover 
 }, 
 { 
 path: &#39;/todayStudy&#39;, 
 component: todayStudy 
 }, 
 { 
 path: &#39;/listenAnyWhere&#39;, 
 component: listen 
 }, 
 { 
 path: &#39;/bought&#39;, 
 component: bought 
 }, 
 { 
 path: &#39;/mine&#39;, 
 component: mine 
 } 
];

先看效果

## 

 

點擊每天聽本書後進入下一級

 

在main.js裡設定二級路由

import thisMouth from &#39;./components/discover/detailEveryDay/thisMouth/thisMouth.vue&#39;; 
import four from &#39;./components/discover/detailEveryDay/fourth/fourth.vue&#39;; 
import three from &#39;./components/discover/detailEveryDay/three/third.vue&#39;; 
import two from &#39;./components/discover/detailEveryDay/two/second.vue&#39;; 
import one from &#39;./components/discover/detailEveryDay/one/first.vue&#39;; 
import twel from &#39;./components/discover/detailEveryDay/twe/twel.vue&#39;; 
import elev from &#39;./components/discover/detailEveryDay/elven/elev.vue&#39;;
const routes = [ 
 { 
 path: &#39;/&#39;, 
 redirect: &#39;/discover&#39; 
 }, 
 { 
 path: &#39;/discover&#39;, 
 component: discover, 
 <span style="color:#ff0000;">children: [ 
  { 
  path: &#39;/&#39;, 
  component: thisMouth 
  }, 
  { 
  path: &#39;/thisMouth&#39;, 
  component: thisMouth 
  }, 
  { 
  path: &#39;/forthMouth&#39;, 
  component: four 
  }, 
  { 
  path: &#39;/thirdMouth&#39;, 
  component: three 
  }, 
  { 
  path: &#39;/secondMouth&#39;, 
  component: two 
  }, 
  { 
  path: &#39;/firstMouth&#39;, 
  component: one 
  }, 
  { 
  path: &#39;/elMouth&#39;, 
  component: twel 
  }, 
  { 
  path: &#39;/twMouth&#39;, 
  component: elev 
  } 
 ]</span> 
 },

在對應的路徑下建立各個路由所需模組即可

 ##上面是我整理給大家的,希望未來會對大家有幫助。

相關文章:

在mint-ui中使用時間外掛程式及取得選擇值

VUE2實現二級省市聯動選擇

在vue中全選實現資料的綁定及取得

#

以上是使用vue實作二級路由設定方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn