欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue路由--網(wǎng)站導(dǎo)航功能詳解

 更新時(shí)間:2019年03月29日 15:01:26   作者:薄荷涼涼涼  
這篇文章主要介紹了vue路由--網(wǎng)站導(dǎo)航功能詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

1、首先需要按照Vue router支持

npm install vue-router
然后需要在項(xiàng)目中引入:

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

2、定義router的js文件

import Vue from 'vue'
import Router from 'vue-router'
import User from '../pages/user'
import Home from '../pages/public/home'
import Profile from '../pages/user/profile'
import Form from '../pages/form'
import Detail from '../pages/form/form'
import File from '../pages/form/file'
import Files from '../pages/file'

Vue.use(Router)

export default new Router({
 routes: [
  { path: '/', component:Home,
   children:[
    { path: '/user', component:Profile},
    { path: '/profile', component: User},
    { path: '/form', component: Form},
    { path: '/detail', component: Detail},
    { path: '/profiles', component: Files},
    { path: '/file', component: File}
   ]
  },

  { path: '/login', component:Login},
  { path: '/404', component:Error}
 ] 
})

3、在main.js中引入router

import router from './router'

new Vue({
 router,
 render: h => h(App),
}).$mount('#app')

4、入口頁(yè)面定義router-view

<div id="app">
 <router-view></router-view>
 </div>

5、在path指向?yàn)椤?”的頁(yè)面中,定義頁(yè)面的布局,例如:上(頭部)-中(左道航-右內(nèi)容)-下(底部)。

<HeaderSection></HeaderSection>
 <div>
  <NavList class="nav"></NavList>
  <router-view class="router"></router-view>
 </div>
<FooterSection></FooterSection>

6、左側(cè)導(dǎo)航,用elementUI實(shí)現(xiàn),有一個(gè)NavMenu導(dǎo)航菜單,做導(dǎo)航功能。

在這里提一下引入elementUI:

(1)安裝

npm i element-ui -S

(2)使用

在main.js中加入下面的代碼:

import ElementUI from 'element-ui';

  import 'element-ui/lib/theme-chalk/index.css';

  Vue.use(ElementUI);

導(dǎo)航欄的代碼如下:

<el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
     text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
 <template v-for="item in items">
  <template v-if="item.subs">
   <el-submenu :index="item.index" :key="item.index">
    <template slot="title">
    <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
    </template>
    <template v-for="subItem in item.subs">
    <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
     <template slot="title">{{ subItem.title }}</template>
     <el-menu-item v-for="(threeItem,i) in subItem.subs" :key="i" :index="threeItem.index">
      {{ threeItem.title }}
     </el-menu-item>
    </el-submenu>
    <el-menu-item v-else :index="subItem.index" :key="subItem.index">
     {{ subItem.title }}
    </el-menu-item>
    </template>
   </el-submenu>
  </template>
  <template v-else>
   <el-menu-item :index="item.index" :key="item.index">
    <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
   </el-menu-item>
  </template>
 </template>
</el-menu>

定義左側(cè)導(dǎo)航的顯示和圖標(biāo)等內(nèi)容,index為唯一標(biāo)識(shí),打開(kāi)的是path路徑,對(duì)應(yīng)router中的path,就可以打開(kāi)寫好的相應(yīng)的頁(yè)面。

items: [
     {
      icon: 'el-icon-share',
      index: 'user',
      title: '系統(tǒng)首頁(yè)'
     },
     {
      icon: 'el-icon-time',
      index: 'profile',
      title: '基礎(chǔ)表格'
     },
     {
      icon: 'el-icon-bell',
      index: '3',
      title: '表單相關(guān)',
      subs: [
       {
        index: 'form',
        title: '基本表單'
       },
       {
        index: '3-2',
        title: '三級(jí)菜單',
        subs: [
         {
          index: 'detail',
          title: '富文本編輯器'
         },
         {
          index: 'file',
          title: 'markdown編輯器'
         },
        ]
       },
       {
        index: 'profiles',
        title: '文件上傳'
       }
      ]
     },
    ]

7、如果涉及到登錄頁(yè)面和不需要路由的頁(yè)面等,就需要在router的js文件中定義和“/”平級(jí)的其他path的頁(yè)面,再判斷進(jìn)入頁(yè)面是路由頁(yè)面還是登錄等頁(yè)面。

以上所述是小編給大家介紹的vue路由--網(wǎng)站導(dǎo)航功能詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Vue 使用beforeEach實(shí)現(xiàn)登錄狀態(tài)檢查功能

    Vue 使用beforeEach實(shí)現(xiàn)登錄狀態(tài)檢查功能

    今天小編就為大家分享一篇Vue 使用beforeEach實(shí)現(xiàn)登錄狀態(tài)檢查功能,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10
  • vue2中filter()的實(shí)現(xiàn)代碼

    vue2中filter()的實(shí)現(xiàn)代碼

    vue2.0里,不再有自帶的過(guò)濾器,需要自己定義過(guò)濾器。下面通過(guò)實(shí)例代碼給大家介紹vue2中filter()的相關(guān)知識(shí),感興趣的朋友一起看看吧
    2017-07-07
  • Vuex 模塊化使用詳解

    Vuex 模塊化使用詳解

    這篇文章主要介紹了Vuex 模塊化使用詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • vue如何搭建多頁(yè)面多系統(tǒng)應(yīng)用

    vue如何搭建多頁(yè)面多系統(tǒng)應(yīng)用

    這篇文章主要為大家詳細(xì)介紹了vue搭建多頁(yè)面多系統(tǒng)應(yīng)用的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • vue使用pdf.js預(yù)覽pdf文件的方法

    vue使用pdf.js預(yù)覽pdf文件的方法

    在頁(yè)面進(jìn)行pdf預(yù)覽的時(shí)候,由于文件不能夠打印和下載很難滿足客戶的需求,接下來(lái)通過(guò)本文給大家介紹vue使用pdf.js來(lái)進(jìn)行pdf預(yù)覽,需要的朋友可以參考下
    2021-12-12
  • vue3中的watch和watchEffect實(shí)例詳解

    vue3中的watch和watchEffect實(shí)例詳解

    watch和watchEffect都是監(jiān)聽(tīng)器,但在寫法和使用上有所區(qū)別,下面這篇文章主要給大家介紹了關(guān)于vue3中watch和watchEffect的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-05-05
  • 淺談vue.watch的觸發(fā)條件是什么

    淺談vue.watch的觸發(fā)條件是什么

    這篇文章主要介紹了淺談vue.watch的觸發(fā)條件是什么?具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • 基于Vue2實(shí)現(xiàn)動(dòng)態(tài)折扣表格

    基于Vue2實(shí)現(xiàn)動(dòng)態(tài)折扣表格

    這篇文章主要為大家詳細(xì)介紹了如何基于Vue2實(shí)現(xiàn)動(dòng)態(tài)折扣表格,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • vue中使用swiper輪播圖的正確姿勢(shì)(親測(cè)有效)

    vue中使用swiper輪播圖的正確姿勢(shì)(親測(cè)有效)

    最近在用Vue制作移動(dòng)端項(xiàng)目,碰到了輪播圖的制作,接下來(lái)就讓小編一步一步帶大家動(dòng)作制作吧,下面這篇文章主要給大家介紹了關(guān)于vue中使用swiper輪播圖的正確姿勢(shì),需要的朋友可以參考下
    2022-06-06
  • 關(guān)于vue設(shè)置環(huán)境變量全流程

    關(guān)于vue設(shè)置環(huán)境變量全流程

    這篇文章主要介紹了關(guān)于vue設(shè)置環(huán)境變量全流程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03

最新評(píng)論