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获取值就好了
}, {