命名视图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <div> <router-link to="/">首页</router-link> <router-link to="/user">用户管理</router-link> <router-link to="/post">帖子管理</router-link> </div> <div> <router-view></router-view> <router-view name="sidebar"></router-view> <router-view name="content"></router-view> </div> </div> <script src="../../lib/vue.js"></script> <script src="../../lib/vue-router.js"></script> <script src="js/main.js"></script> </body> </html>
var routes = [ { path: "/", component: { template: ` <h1>首页管理</h1> ` } }, { path:"/user", components:{ sidebar:{ template:` <div> <ul> <li>用户列表</li> <li>权限管理</li> </ul> </div> ` }, content:{ template:` <div> 主要的文本去,分区 </div> ` } } }, { path:"/post", components:{ sidebar:{ template:` <div> <ul> <li>帖子列表</li> <li>帖子管理</li> </ul> </div> ` }, content:{ template:` <div> 主要的文本去,分区 </div> ` } } } ]; var router = new VueRouter({ routes: routes }); new Vue({ el: "#app", router: router, })
本文来自博客园,作者:一石数字欠我15w!!!,转载请注明原文链接:https://www.cnblogs.com/52-qq/p/8387643.html