056——VUE中vue-router之路由参数的验证处理保存路由安全
<!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> <br/> <router-view></router-view> </div> <script type="text/x-template" id="content"> <div> id:{{$route.params.id}} <br/> <button @click="show">点击效果</button> </div> </script> <script> const content = { template: "#content", methods: { show() { console.log(this.$route.params); } } } let routes = [ {path: '/content/:id(\\d{2})', component: content} ] let router=new VueRouter({routes}); new Vue({ el: "#demo", router }); </script> </body> </html>