vue中路由跳转 声明式:<router-link :to="{name:‘index‘}}"> 或者 <router-link to=‘/index‘> 编程式:router.push(...) 方法一: this.$router.push({path:‘路径‘)};(自己常用) 方法二:this.$router.push({name:‘组件名‘)}; 2.需求:点击按钮,跳转到任意页面(传参) 声明式:<router-link :to="{name:‘index‘,query:{id:‘xxx‘,name:‘xxx‘}}"> 编程式:router.push(...) 方法一:this.$router.push({path:‘xxx‘,query:{aa:xx, bb: xx}}); //带查询参数,类似于 “?” 的形式传值 方法二:this.$router.push({path:‘xxx‘,params:{aa:xx, bb: xx}}); 注:以上两种方法的query跳转路径也可以写成name:‘组件名‘的形式 在query中放入需要传递的参数即可,多个参数之间用逗号隔开; 取值:this.$route.query.xx (可在跳转的页面取得所传递的值); eg1: 跳转并传值:this.$router.push({path:‘index‘,query:{id:‘123‘}); // 带查询参数,变成/index?id=123 取值:this.$route.query.id ; eg2: 跳转并传值:this.$router.push({path:‘xxx‘,params:{id:‘123‘}); 取值:this.$route.params.id ;
原文:https://www.cnblogs.com/zlp520/p/14090687.html