<router-link to='/index'>
<Button>跳转</Button>
</router-link>
<Button @click='go'></Button>
go () {
this.$router.push({
path: '/index'
})
}
传参
this.$router.push({path: '/order/page1',query:{ id:'2'}});
this.$router.push({name: '/order/page2',params:{ id:'6'}});
// path:’路由里配置的index.vue的路径’
// params:{id:’1’,name:’eva’} /query:{id:’5’} 需要传递的参数和值
路由传参params 和query两种方式的区别:
1、用法上的
刚才已经说了,query要用path来引入,params要用name来引入,接收参数都是类似的,分别是this.route.query.name和this.route.query.name和this.route.params.name。
注意接收参数的时候,已经是route而不是route而不是router了哦!!
2、展示上的
query更加类似于我们ajax中get传参,params则类似于post,说的再简单一点,前者在浏览器地址栏中显示参数,后者则不显示
路由参数的取值:
{{this.$route.params.参数名}}
注:注意接收参数的时候,已经是route而不是route而不是router了哦!!