学习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"> <!-- 路由可以自己传参数 --> <!--<transition mode="out-in"> <router-view></router-view> </transition> --> <router-link to="/account" tag="span">展示大路由组件</router-link> <router-view></router-view> </div> <template id="account"> <div> <h1>我是大路由</h1> <router-link to="/account/login" tag="span">小login</router-link> <router-link to="/account/register" tag="span">小register</router-link> <router-view></router-view> </div> </template> <script> // 大组件模板对象 var com={ template:"#account" } var login={ template:"<div class='a'>login---id-{{$route.params.id}}name--{{$route.params.name}}</div>", created(){ // 通过$route.params 方法得到参数 console.log(this.$route.params.id) } } var register={ template:"<div class='b'>register</div>" } // 2.创建路由对象 var rout=new VueRouter({ routes:[ { path:"/account", component:com, children:[//子路由嵌套。不用加" / " {path:"login",component:login}, {path:"register",component:register} ] }, ], linkActiveClass:'myactive' }) // 创建 Vue 实例,得到 ViewModel var vm = new Vue({ el: '#app', data: {}, methods: {}, router: rout // 将路由规则对象,注册到 vm 实例上,用来监听 URL 地址的变化,然后展示对应的组件 }); </script> </body> </html>
标签:vue,color,register,嵌套,第二十四,var,params,login,路由 来源: https://www.cnblogs.com/shangrao/p/13088756.html