嵌套路由
Posted m-yk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了嵌套路由相关的知识,希望对你有一定的参考价值。
嵌套路由指的是在动态路由的基础上再加上附加的嵌套URL(即组件)。
<template> <div> <p>{{msg}}</p> <router-link :to="profile">简介</router-link> <router-link :to="stats">数据</router-link> <router-view></router-view> </div> </template> <script> export default{ name:‘player‘, data(){ return { msg:{}, profile:‘‘, stats:‘‘ } }, mounted(){ this.msg=this.getPlayer(this.$route.params.uid); this.profile=‘/player/‘+this.$route.params.uid+‘/profile‘; this.stats=‘/player/‘+this.$route.params.uid+‘/stats‘; }, beforeRouteUpdate(to,from,next){ this.msg=this.getPlayer(to.params.uid); this.profile=‘/player/‘+to.params.uid+‘/profile‘; this.stats=‘/player/‘+to.params.uid+‘/stats‘; next(); }, methods:{ getPlayer(uid){ switch (uid) { case ‘1‘: return {id:1,name:‘哈登‘}; break; case ‘2‘: return {id:2,name:‘姚明‘}; break; default: return {id:-1}; // statements_def break; } } } } </script>
以上是关于嵌套路由的主要内容,如果未能解决你的问题,请参考以下文章