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

vue路由嵌套的SPA實(shí)現(xiàn)步驟

 更新時間:2017年11月06日 11:01:04   作者:匿名的girl  
這篇文章主要為大家詳細(xì)介紹了vue路由嵌套的SPA實(shí)現(xiàn)步驟,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分享了路由嵌套的SPA實(shí)現(xiàn)的步驟:

A(/a)組件需要嵌套B組件(/b)和C組件(/c)

①準(zhǔn)備嵌套其它組價(jià)的父組件 指定一個容器

在A組件指定一個容器
<router-view></router-ivew>

②在A組件的路由配置對象中指定children屬性

{
path:'/a',
component:A,
children:[
{path:'/b',component:B},
{path:'/c',component:C},
]
}

補(bǔ)充:

//數(shù)字如果超出記錄的次數(shù),是不行的。
this.$router.go(num);
如果num是正數(shù),向前進(jìn)
如果num是負(fù)數(shù),向后退

代碼

<!doctype html>
<html>
 <head>
 <meta charset="UTF-8">
 <title>路由嵌套</title>
  <script src="js/vue.js"></script>
  <script src="js/vue-router.js"></script>
 </head>
 <body>
 <div id="container">
    <p>{{msg}}</p>
    <router-view></router-view>
  </div>
  <script>
//登錄組件
    var myLogin = Vue.component("login",{
      template:`
        <div>
          <h1>登錄組件</h1>
          <router-link to="/mail">登錄</router-link>
        </div>
    `
    })
//  郵箱頁面
    var myMail = Vue.component("mail",{
//    定義一個返回的方法
      methods:{
        goBack:function(){
          this.$router.go(-1);
        }
      },
      template:`
        <div>
          <h1>郵箱主頁面</h1>
          <ul>
            <li>
              <router-link to="/inbox">收件箱</router-link>
            </li>
            <li>
              <router-link to="/outbox">發(fā)件箱</router-link>
            </li>
          </ul>
//        點(diǎn)擊按鈕返回前面的頁面
          <button @click="goBack">返回</button>
          <router-view></router-view>
        </div>
    `
//  指定一個容器,加載收件箱或收件箱的列表
    })
//  收件箱組件
    var myInBox = Vue.component("inbox-component",{
      template:`
        <div>
          <h4>收件箱</h4>
          <ul>
            <li>未讀郵件1</li>
            <li>未讀郵件2</li>
            <li>未讀郵件3</li>
          </ul>
        </div>
    `
    })
//  發(fā)件箱組件
    var myOutBox = Vue.component("outbox-component",{
      template:`
        <div>
          <h4>發(fā)件箱</h4>
          <ul>
            <li>已發(fā)送郵件1</li>
            <li>已發(fā)送郵件2</li>
            <li>已發(fā)送郵件3</li>
          </ul>
        </div>
    `
    })
    //配置路由詞典
    new Vue({
      router:new VueRouter({
        routes:[
          {path:'',redirect:'/login'},
          {path:'/login',component:myLogin},
          {path:'/mail',component:myMail,children:[
            {path:'/inbox',component:myInBox},
            {path:'/outbox',component:myOutBox}
        ]},
        ]
      }),
      el:"#container",
      data:{
        msg:"Hello VueJs"
      }
    })
    //通過再次指定一個<router-view></router-view>和children:[]
  </script>
 </body>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

兴业县| 体育| 仁寿县| 合肥市| 马山县| 盐山县| 洞头县| 芜湖市| 嘉荫县| 昆山市| 正定县| 泗阳县| 桐庐县| 腾冲县| 佳木斯市| 长海县| 镇坪县| 孟村| 天津市| 顺昌县| 灵台县| 太仓市| 松滋市| 哈密市| 余江县| 宁明县| 江陵县| 新和县| 方山县| 南陵县| 溧水县| 自贡市| 永登县| 高陵县| 满洲里市| 红安县| 石景山区| 珲春市| 蒙城县| 安徽省| 绥化市|