- vue动态路由跳转有push、replace等方法。最近有个需求是需要从不同的路由点击某个操作按钮进行路由跳转。
- 之前用的是replace方法,因为要带参数,想到的办法是用模板字符串把所有的参数拼接在地址栏上传参过去。
this.$router.replace(
{
'/service/intelligentAlarmDetail?alarmType='+alarmType+
'&unitId='+row.typeNo+
'&unitName='+row.typeName+
'&startTime='+new Date(startTime).getTime()+
'&endTime='+new Date(endTime).getTime()+
'&type=3'+
'&tabIndex=0&key=1'
);
后来发现这样跳转了之后不但回不去之前的页面,而且地址栏上一大堆的数据。
- 百度了之后,决定用push方法,push传参有两种方式,一种是query,另一种是params。在跳转了之后的页面直接
this.$route.query/this.$route.params
,可以取参数。 - query参数还是会在地址栏上显示。用法:this.$router.push(path:/service/intelligentAlarmDetail,query:参数对象)
- params参数不会在地址栏显示,但是能和path同时使用,会不生效。用法:this.$router.push(name:IntelligentAlarmDetail,params:参数对象)