vue 路由之间传值 (编程式导航)

来源:互联网 发布:为什么淘宝网打不开 编辑:程序博客网 时间:2024/06/05 10:34

//params形式:参数不显示在地址栏

this.$router.push({ name: 'details', params: { userId: this.num }}) //'details'是路由名;'userId'是传入的参数

//获取
console.log(this.$route.params.userId);

//query形式:参数显示在地址栏

 this.$router.push({ path: 'details', query: { userId: this.num }})

//获取
console.log(this.$route.query.userId);

//params 形式取 path:’/login’
//query 形式取 name:’登录’
如图:
这里写图片描述

官网地址:编程式导航:https://router.vuejs.org/zh-cn/essentials/navigation.html