vue路由重复点击报错
发表于:2022-12-27 | 分类: 前端
字数统计: 94 | 阅读时长: 1分钟 | 阅读量:

通过 $router.push() 的方式跳转路由时,路由重复点击会报错

解决办法

  1. routerindex.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)
    }
  2. 在使用 $router.push()catch 一下 err :
    1
    this.$router.push({}).catch(err => {})
上一篇:
echarts鼠标首次悬浮经过页面闪动
下一篇:
antVL7可视化开发问题