1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > vue-router-2-动态路由配置

vue-router-2-动态路由配置

时间:2022-03-10 18:03:38

相关推荐

vue-router-2-动态路由配置

constUser= {template: '<div>User{{ $route.params.id }}</div>'}const router =newVueRouter({routes: [// 动态路径参数 以冒号开头{ path: '/user/:id', component:User}]})

//多段『路径参数』,对应的值都会设置到 $route.params 中/user/:username/post/:post_id

//路由参数变化,组件复用时,可以用watch处理const User = {template: '...',watch: {'$route' (to, from) {// 对路由变化作出响应... }}}

或者使用beforeRouteUpdateconst User = {template: '...',beforeRouteUpdate(to, from, next) {// react to route changes...// don't forget to call next() }}

同一个路径可以匹配多个路由,谁先定义的,谁的优先级就最高。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。