通过 $router.push() 的方式跳转路由时,路由重复点击会报错
解决办法:
- 在
router的index.js文件中use router之前加入以下代码 :1
2
3
4
5
6
7
8//router/index.js
import Router from "vue-router"
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
} - 在使用
$router.push()时catch一下err:1
this.$router.push({}).catch(err => {})