美文网首页前端开发那些事儿
vue之this.$route.query和this.$rout

vue之this.$route.query和this.$rout

作者: vivianXIa | 来源:发表于2019-04-28 11:55 被阅读0次

一、this.$route.query的使用

1、router/index.js

{
path:'/mtindex',
component: mtindex,
//添加路由
children:[
 {
    path:':shopid',
    component:guessdetail
 }
]       

},

2、传参数

this.$router.push({
      path: '/mtindex/detail', query:{shopid: item.id}

        });

3、获取参数

this.$route.query.shopid

4、url的表现形式(url中带有参数)

http://localhost:8080/#/mtindex/detail?shopid=1

二、this.$route.params

1、router/index.js

{
    path:'/mtindex',
    component: mtindex,
    //添加路由
    children:[
     {
        path:"/detail",
        name:'detail',
        component:guessdetail
     }
    ]       

    },

2、传参数( params相对应的是name query相对应的是path)

this.$router.push({
      name: 'detail', params:{shopid: item.id}

        });

3、获取参数

this.$route.params.shopid

4、url的表现形式(url中没带参数)

http://localhost:8080/#/mtindex

作者:小水91
来源:CSDN
原文:https://blog.csdn.net/lsy__lsy/article/details/79991955

相关文章

网友评论

    本文标题:vue之this.$route.query和this.$rout

    本文链接:https://www.haomeiwen.com/subject/ucldnqtx.html