$router 和 r o u t e 的 区 别 route的区别 route的区别 route为当前router跳转对象里面可以获取name、path、query、params等
r o u t e r 为 V u e R o u t e r 实 例 , 想 要 导 航 到 不 同 U R L , 则 使 用 router为VueRouter实例,想要导航到不同URL,则使用 router为VueRouter实例,想要导航到不同URL,则使用router.push方法
返回上一个history也是使用$router.go方法
$router.push()
1.params 传参
注意⚠️:patams传参 ,路径不能使用path 只能使用name,不然获取不到传的数据
1
this.
r
o
u
t
e
r
.
p
u
s
h
(
n
a
m
e
:
′
i
n
d
e
x
′
,
p
a
r
a
m
s
:
i
d
:
1
)
取
数
据
:
t
h
i
s
.
router.push({name: 'index', params: {id: 1}}) 取数据:this.
router.push(name:′index′,params:id:1) 取数据:this.route.params.id
2.query传参
1
this.
r
o
u
t
e
r
.
p
u
s
h
(
p
a
t
h
:
′
g
o
o
d
′
,
q
u
e
r
y
:
i
d
:
2
)
取
数
据
:
t
h
i
s
.
router.push({path: 'good', query: {id: 2}}) 取数据:this.
router.push(path:′good′,query:id:2) 取数据:this.route.query.id