日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue之二级路由

發布時間:2025/3/15 vue 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue之二级路由 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?router-view :??

  <router-view>?組件是一個 functional 組件,渲染路徑匹配到的視圖組件

  一 樣式

  1 在一個vue組件,<template></template>中,在加入<router-view></router-view>

    <template>

      <div>

        .......

        <router-view></router-view>

      </div>  

    </template>

  2 在路由中 router/index.js 中,

    {

      path:'/xx',

      name:'',

      component:xx,

      children:[

            path:' oo '? ? ? ?注意:沒有 /

            name:' oo',? ? ?這個是用于反向查找,? 組件中? <router-link :to="{name:'oo'}">oo</router-link>,? name對應的就是 路由中的name。注意 是 :to = " { name:' oo'}"

            component:oo,? 從前到后找到這個組件,先一級組件,在二級組件

          ]

    }

  3 每一個 二級路由都對應獨自的 vue組件。

  通過反向查找,先加載一級路由"xx",在加載二級路由"oo"。

二 代碼示例

  App.vue

  

<template><div id="app"><Header></Header><router-view></router-view><Footer></Footer></div> </template><script>import Header from './components/Header.vue'import Footer from './components/Footer.vue' export default {name: 'App',components:{Header,Footer,} } </script><style></style>

  路由

Vue.use(Router)export default new Router({mode:'history',routes: [{path: '/',name: 'index',component: Index,},{path: '/index',name: 'index',component: Index,},{path: '/course',name: 'course',component: Course,},{path: '/news',name: 'news',component: News,},{path: '/help',name: 'help',component: Help,children:[{path: 'aboutus',name: 'aboutus',component: Aboutus,},{path: 'feedback',name: 'feedback',component: Feedback,},{path: 'usernote',name: 'usernote',component: Usernote,},]},] })

 項目結構

  

  help.vue

<template><div><p>{{msg}}</p><router-view></router-view></div> </template><script>export default{name:'help',data(){return{msg:'這是幫助信息',}}} </script><style></style>

?

三 有什么用

  當指向不同的url時,部分頁面是相同的,部分頁面才需要改變,這個時候,用二級路由比較合適。 不變的放在一級,需要變化的放在二級。

轉載于:https://www.cnblogs.com/654321cc/p/8568685.html

總結

以上是生活随笔為你收集整理的vue之二级路由的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。