vue this.$route.query 和this.$route.params的使用与区别

发布时间 2023-05-29 14:17:16作者: 唏嘘-
一:this.$route.query的使用
#1、传参数:
this.$router.push({
        path: '/index/detail', 
        query:{itemId: item.id}
});  

#2、获取参数
this.$route.query.itemId

#3、url的表现形式
http://localhost:8080/#/index/detail?itemId=22

二:this.$route.params的使用
#1、传参数( params相对应的是name  query相对应的是path)
this.$router.push({
        name: 'detail', 
        params:{itemId: item.id}
});

#2、获取参数
this.$route.params.itemId

#3、url的表现形式(url中没带参数)
http://localhost:8080/#/index/detail