日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

vue 当前路由重复点击跳转报错

發(fā)布時間:2024/3/12 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue 当前路由重复点击跳转报错 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

當菜單路由重復點擊時,會出現以下報錯:

雖然沒有什么影響(不知道深層有什么影響,頁面運行反正沒啥問題),但是有個報錯看著就畢竟鬧心。
有以下解決方案:

  • router配置中添加代碼塊不再報錯
  • // 解決Vue-Router升級導致的Uncaught(in promise) navigation guard問題 const originalPush = VueRouter.prototype.push; VueRouter.prototype.push = function push(location, onResolve, onReject) {if (onResolve || onReject)return originalPush.call(this, location, onResolve, onReject);return originalPush.call(this, location).catch((err) => err); };
  • 增加刷新頁面,重新加載當前頁
    刷新頁面
  • <!-- 空頁面,負責中轉到目標頁面 --> <template><div></div> </template><script> export default {name: 'refresh',data() {return {};},beforeRouteEnter(to, from, next) {next((vm) => {vm.$router.replace(from.path);});}, }; </script>

    路由

    {path: "/refresh",name: "refresh",hideInMenu: true,component: () =>import( /* webpackChunkName: "login" */ "@/components/refresh/refresh"), },

    菜單跳轉時

    routeJump(item) {const toPath = item.path;const thePath = this.$route.path;if (toPath == thePath) {this.$router.replace({ path: '/refresh' });} else {this.$router.push({ name: item.name });}},

    如果當前路由與跳轉路由相同,則跳轉到refresh頁面中,再跳回原頁面,重新加載一次當前路由。

    總結

    以上是生活随笔為你收集整理的vue 当前路由重复点击跳转报错的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。