学习vue第二十五节,路由同级排列

 

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="lib/vue-2.4.0.js"></script>
  <!-- 1. 安装 vue-router 路由模块 -->
  <script src="lib/vue-router-3.0.1.js"></script>
  <style>
      
      /* 
      当展示哪个路由,router-link标签就会加上两个class
       router-link-exact-active router-link-active
       */
    .myactive {
      background-color: #1B6D85;
    }
  .myactive2 {
      background-color: #5500ff;
    }

    .v-enter,
    .v-leave-to {
      opacity: 0;
      transform: translateX(140px);
    }

    .v-enter-active,
    .v-leave-active {
      transition: all 0.5s ease;
    }
    .a{
        width: 200px;
        height: 200px;
        background-color: red;
    }
    .b{
        width: 200px;
        height: 200px;
        background-color: green;
    }
  </style>
</head>

<body>
  <div id="app">
     
        <router-view name="com1"></router-view>
        <router-view name="com2"></router-view>
        <router-view name="com3"></router-view>
  </div>
        

  <script>
      // 大组件模板对象      
    var h1={
        template:"<h1>11111111</h1>"
    }  
      
    var h2={
        template:"<h1>2222222</h1>",        
    }
   var h3={
       template:"<h1>33333333333</h1>"
   }
   
   // 2.创建路由对象  
   var rout=new VueRouter({
       routes:[         
           {
               path:"/",
               components:{//加 components 属性,值为对象,
                   'com1':h1,
                   'com2':h2,
                   'com3':h3
               }                         
            },           
       ]
      
   })
    
    // 创建 Vue 实例,得到 ViewModel
    var vm = new Vue({
      el: '#app',
      data: {},
      methods: {},
      router: rout // 将路由规则对象,注册到 vm 实例上,用来监听 URL 地址的变化,然后展示对应的组件
    });
  </script>
</body>

</html>

 

posted @ 2020-06-10 20:46  三线码工  阅读(415)  评论(0编辑  收藏  举报