Vue-router传参可以分为两大类,分别是编程式的导航 router.push和声明式的导航
编程式的导航 router.push
1)字符串:直接传递路由地址,但是不能传递参数
this.$router.push("home")
2)对象:
命名路由 这种方式传递参数,目标页面刷新会报错 - name+params
this.$router.push({name:"news",params:{userId:123})
查询参数 和path配对的是query
this.$router.push({path:"/news',query:{uersId:123})
接收参数 this.$route.query
声明式导航
字符串 <router-link to:"news"></router-link>
命名路由 <router-link :to:"{name:'news',params:{userid:1111}}"></route-link>
还可以to="/path/值" - 需要提前在路由 规则里值 /path/:key
查询参数 <router-link :to="{path:'/news',query:{userId:1111}}"></router-link>
还可以to="/path?key=value