最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue-路由精講 二級路由和三級路由的作用

 更新時(shí)間:2020年08月06日 10:50:37   作者:甘劭  
這篇文章主要介紹了vue-路由精講 二級路由和三級路由的作用,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

1、我們繼續(xù)上一個案例 vue -- 路由精講制作導(dǎo)航 -- 從無到有 ,在 about文件夾下 創(chuàng)建一些文件夾。如下:

2、編寫about.vue代碼。當(dāng)我們點(diǎn)擊導(dǎo)航中 “關(guān)于我們” ,就會顯示該部分內(nèi)容。代碼中寫了四個可供點(diǎn)擊后可以跳轉(zhuǎn)的模塊。和 <router-view></router-view> 表示你點(diǎn)擊了哪個組件,哪個組件就會渲染到這里來。

其中注意:css樣式,我們直接引入bootstrap中的導(dǎo)航的樣式,在標(biāo)簽中直接添加class屬性的值就可以了。

about.vue代碼

<template>
  <div>
    <div class="row mb-5">  //row 代表行, mb-5 表示margin-bottom距離下面5
      <!-- 導(dǎo)航 -->
      <div class="col-4"> //四列
        <div class="list-group mb-5">
          <router-link tag="li" class="nav-link" :to="{name:'historyLink'}">
            <a class="list-group-item list-group-item-action">歷史訂單</a>  
          </router-link>
          <router-link tag="li" class="nav-link" :to="{name:'contactLink'}">
            <a class="list-group-item list-group-item-action">聯(lián)系我們</a>  
          </router-link>
          <router-link tag="li" class="nav-link" :to="{name:'orderingGuideLink'}">
            <a class="list-group-item list-group-item-action">點(diǎn)餐文檔</a>  
          </router-link>
          <router-link tag="li" class="nav-link" :to="{name:'deliveryLink'}">
            <a class="list-group-item list-group-item-action">快遞信息</a>  
          </router-link>
        </div>
      </div>
      <!-- 導(dǎo)航所對應(yīng)的內(nèi)容 -->
      <div class="col-8"> //8列
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

3、配置二級路由和三級路由

注意:我們要在about頁面下添加四個路由,用到 children 屬性, 而且還用到 redirect 屬性,默認(rèn)跳轉(zhuǎn)到指定路由,具體操作看代碼和注釋。

main.js代碼

import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
import Home from './components/Home.vue'
import Menu from './components/Menu.vue'
import Admin from './components/Admin.vue'
import About from './components/about/About.vue'
import Login from './components/Login.vue'
import Register from './components/Register.vue'

//二級路由
import Contact from './components/about/Contact.vue'
import Delivery from './components/about/Delivery.vue'
import History from './components/about/History.vue'
import OrderingGuide from './components/about/OrderingGuide.vue'

//三級路由
import Phone from './components/about/contact/Phone.vue'
import PersonName from './components/about/contact/PersonName.vue'

Vue.use(VueRouter)

核心代碼 二級路由和三級路由的跳轉(zhuǎn)

const routes = [
  {path:'/',   name:'homeLink',  component:Home},
  {path:'/menu', name:'menuLink',  component:Menu},
  {path:'/admin', name:'adminLink', component:Admin},
  {path:'/about', name:'aboutLink', redirect:'/about/contact', component:About, children:[      
                       //表示about頁面中默認(rèn)跳轉(zhuǎn)到/about/contact 這個路由頁面下。
    {path:'/about/contact', name:'contactLink', redirect:'/personName', component:Contact, children:[
                       //在/about/contact頁面中默認(rèn)展現(xiàn)三級路由personName 的內(nèi)容。
      {path:'/phone', name:"phoneNumber", component:Phone},
      {path:'/personName', name:"personName", component:PersonName},
    ]},
    {path:'/history',name:'historyLink',component:History},
    {path:'/delivery',name:'deliveryLink',component:Delivery},
    {path:'/orderingGuide',name:'orderingGuideLink',component:OrderingGuide},
  ]},
  {path:'/login', name:'loginLink', component:Login},
  {path:'/register', name:'registerLink', component:Register},
  // {path:'*',redirect:'/'},
]

const router = new VueRouter({
  routes,
  mode:'history'
})

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

Contact.vue代碼

<template>
  <div class="card text-dark bg-light mb-3">
    <div class="card-header">聯(lián)系我們</div>
    <div class="card-body">
      <h4 class="card-title">聯(lián)系我們</h4>
      <p class="card-text">1623487989@qq.com</p>

      <router-link :to="{name:'phoneNumber'}">電話</router-link>
      <router-link :to="{name:'personName'}">聯(lián)系人</router-link>

      <router-view></router-view>
    </div>
  </div>
</template>

Delivery.vue代碼

<template>
  <div class="card text-dark bg-light mb-3">
    <div class="card-header">快遞信息</div>
    <div class="card-body">
      <h4 class="card-title">快遞信息</h4>
      <p class="card-text">1623487989@qq.com</p>
    </div>
  </div>
</template>

History.vue代碼

<template>
  <div class="card text-dark bg-light mb-3">
    <div class="card-header">歷史訂單</div>
    <div class="card-body">
      <h4 class="card-title">歷史訂單</h4>
      <p class="card-text">1623487989@qq.com</p>
    </div>
  </div>
</template>

OrderingGuide.vue代碼

<template>
  <div class="card text-dark bg-light mb-3">
    <div class="card-header">點(diǎn)餐文檔</div>
    <div class="card-body">
      <h4 class="card-title">點(diǎn)餐文檔</h4>
      <p class="card-text">1623487989@qq.com</p>
    </div>
  </div>
</template>

Phone.vue代碼

<template> <h1>400040040404404</h1> </template>

PersonName.vue代碼

<template> <h1>小劭</h1> </template>

補(bǔ)充知識:vue:菜單收縮功能

想要實(shí)現(xiàn):點(diǎn)擊菜單能收縮。(效果如下:)

點(diǎn)擊前:

點(diǎn)擊后:

思路:

首先我們要知道紳縮的按鈕和菜單是否在一個頁面。在一個頁面就簡單了。

如果不在一個頁面,就會涉級到父子級傳參,紳縮按鈕模塊中要把狀態(tài)傳給header,這是兄弟間的傳遞參數(shù),需要用到 vuex。如果不用vuex的話,就通過主體去操作。紳縮按鈕把狀態(tài)傳給主體是子傳父,通過 this.$emit()。主體把狀態(tài)傳給菜單,是父傳子,通過props ,菜單中需要接收主體中傳過來的東西,要在 data 中定義props 在里面定義type、required、default。如果不清楚props 是啥,請百度。

操作:

1、先看整體布局

2、menu 模塊

3、header 模塊

以上這篇vue-路由精講 二級路由和三級路由的作用就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Vue中keep-alive的使用

    詳解Vue中keep-alive的使用

    keep-alive是Vue的內(nèi)置組件,當(dāng)它包裹動態(tài)組件時(shí),會緩存不活動的組件實(shí)例,而不是銷毀,這篇文章主要介紹了詳解Vue中keep-alive的使用,需要的朋友可以參考下
    2023-03-03
  • vue更改數(shù)組中的值實(shí)例代碼詳解

    vue更改數(shù)組中的值實(shí)例代碼詳解

    這篇文章主要介紹了vue更改數(shù)組中的值,本文通過兩個例子,給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • vue3+vue-cli4中使用svg的方式詳解(親測可用)

    vue3+vue-cli4中使用svg的方式詳解(親測可用)

    最近在做個vue的項(xiàng)目,從各種github上的開源庫上借鑒開發(fā)方法,給大家分享下,這篇文章主要給大家介紹了關(guān)于vue3+vue-cli4中使用svg的相關(guān)資料,需要的朋友可以參考下
    2022-08-08
  • Vue.extend 登錄注冊模態(tài)框的實(shí)現(xiàn)

    Vue.extend 登錄注冊模態(tài)框的實(shí)現(xiàn)

    這篇文章主要介紹了Vue.extend 登錄注冊模態(tài)框的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Vue.js每天必學(xué)之過濾器與自定義過濾器

    Vue.js每天必學(xué)之過濾器與自定義過濾器

    Vue.js每天必學(xué)之過濾器與自定義過濾器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Vue2.0 多 Tab切換組件的封裝實(shí)例

    Vue2.0 多 Tab切換組件的封裝實(shí)例

    本篇文章主要介紹了Vue2.0 多 Tab切換組件的封裝實(shí)例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • vue中component組件的props使用詳解

    vue中component組件的props使用詳解

    本篇文章主要介紹了vue中component組件的props使用詳解,這里整理了詳細(xì)的用法,具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-09-09
  • 詳細(xì)講解如何創(chuàng)建, 發(fā)布自己的 Vue UI 組件庫

    詳細(xì)講解如何創(chuàng)建, 發(fā)布自己的 Vue UI 組件庫

    當(dāng)我們自己開發(fā)了一個 _UI Component_, 需要在多個項(xiàng)目中使用的時(shí)候呢? 我們首先想到的可能是直接復(fù)制一份過去對嗎?我們?yōu)槭裁床话l(fā)布一個 UI 組件庫給自己用呢?下面小編和大家來一起學(xué)習(xí)下吧
    2019-05-05
  • 如何讓別人訪問本地運(yùn)行的vue項(xiàng)目

    如何讓別人訪問本地運(yùn)行的vue項(xiàng)目

    這篇文章主要介紹了如何讓別人訪問本地運(yùn)行的vue項(xiàng)目,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • Vue echart實(shí)現(xiàn)柱狀圖,電池圖,3D柱圖和3D圓柱圖代碼詳解

    Vue echart實(shí)現(xiàn)柱狀圖,電池圖,3D柱圖和3D圓柱圖代碼詳解

    這篇文章主要為大家介紹了Vue實(shí)現(xiàn)echart繪圖代碼詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-01-01

最新評論

武陟县| 宜都市| 巴南区| 临江市| 景泰县| 固始县| 新昌县| 南漳县| 乳山市| 永州市| 嫩江县| 安康市| 鄄城县| 开江县| 贵州省| 襄樊市| 遂昌县| 正镶白旗| 郓城县| 乌审旗| 杭锦后旗| 通辽市| 平原县| 桐城市| 丰原市| 遂宁市| 鹰潭市| 太原市| 南部县| 英德市| 洪湖市| 湘阴县| 额尔古纳市| 阿瓦提县| 即墨市| 明光市| 浮山县| 平远县| 若羌县| 包头市| 大竹县|