<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>vue-router之路由参数默认值的设置</title> <script src="vue.js"></script> <script src="vue-router.js"></script> </head> <body> <div id="demo"> <router-link to="/content">链接</router-link> <router-view></router-view> </div> <script type="text/x-template" id="content"> <div> id:{{id}} </div> </script> <script> const content = { template: "#content", data() { return { id:0 } }, mounted() { this.id = this.$route.params.id; if (!this.id) { this.id = 1; } } } let routes=[ {path:'/content/:id?',component:content} ] let router=new VueRouter({routes}); new Vue({ el:"#demo", router }); </script> </body> </html>