放在路劲上进行取值:
方法一:{
path: ‘/detail/:id’,
name: ‘detail’,
component: () =>import(’@/components/detail.vue’)
},
在控制台打印console.log(this.$route)的值会得到:
这里的id是自己在跳转路由所传的值
this.$router.push({path:/detail/ni})
方法二:
在跳转页面的时候同时赋值:this.
r
o
u
t
e
r
.
p
u
s
h
(
p
a
t
h
:
/
d
e
t
a
i
l
,
q
u
e
r
y
:
i
d
:
′
′
)
在
进
入
页
面
之
前
获
取
到
上
一
个
页
面
传
递
过
来
的
值
:
t
h
i
s
.
router.push({path:/detail,query:{id:''}}) 在进入页面之前获取到上一个页面传递过来的值:this.
router.push(path:/detail,query:id:′′)在进入页面之前获取到上一个页面传递过来的值:this.route.query.id