<div id="app"> <p>$route.name: {{$route.name}}</p> <p>$route.path: {{$route.path}}</p> <p>$route.query: {{$route.query}}</p> </div> <script src="/static/js/vue.js"></script> <script src="/static/js/vue-router.js"></script> <script> const router = new VueRouter({ mode: "history", // 默认使用hash模式,url会出现# }); const app = new Vue({ router, el: "#app", }); </script>
显示结果
$route.name: $route.path: /demo.html $route.query: { "id": "44", "name": "Tom" }
单页面上使用vue-router,可以用来解析url上的参数