这个的原因是因为你重复跳转到了同样的一个路由中,所以才会出现这个问题。解决如下:
getMessage(){
this.$router.push({
name:'about',
params:{
keyWord:12345
},
query:{
age:18
}
}).catch(()=>{
alert('请勿重复跳转同一个路由')
})
}
因为router是一个promise,所以可以通过catch来捕获失败的内容。
解决相同路由跳转失败的问题
- 将router上的push进行重写即可实现跳转
VueRouter.prototype.push = function (location) {
return originalPush.call(this, location).catch(err => err)
}