vue2.x路由传参方法总结

1、采用<router-link> 标签中的to传参

传递的页面

<router-link :to="{'name':'addClue', params: {'type': 1}}"></router-link>

 

router.js中

    path: 'addClue/:type',

    name: 'addClue',

component: addClue

其中path是否可以不加上:type有待商量

 

获取参数的页面:

This.$route.params.type获取值就好了

 

2、利用url传递参数

传递的页面

This.$router.push({name: 'addClue', params: {type: 1} })

 

router.js中

    path: 'addClue/:type',

    name: 'addClue',

component:()=>import('../components/addClue.vue')

 

获取参数的页面:

This.$route.params.type获取值就好了

 

3、用name匹配路由,params传参(很少使用)

传递的页面

This.$router.push({name: 'addClue', params: {type: 1}} )

 

router.js中

    path: 'addClue',

    name: 'addClue',

component: resolve => require(['../components/addClue.vue'], resolve),

 

获取参数的页面:

This.$route.params.type获取值就好了

 

4、用query传参(推荐)

传递的页面

This.$router.push({name: 'addClue', query: {type: 1}} )

 

router.js中

    path: 'addClue',

    name: 'addClue',

component:()=>import('../components/addClue.vue')

 

获取参数的页面:

this.$route.query.type获取值就好了

 

5、用meta传参(推荐)

router.js中

    path: 'addClue',

name: 'addClue',

meta: { showClose: false, checkLogin: false },

component:addClue

获取参数的页面:

This.$route.meta获取值就好了

 

 

 

 

      }, {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值