日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

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

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

當菜單路由重復點擊時,會出現(xiàn)以下報錯:

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

  • 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); };
  • 增加刷新頁面,重新加載當前頁
    刷新頁面
  • <!-- 空頁面,負責中轉(zhuǎn)到目標頁面 --> <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"), },

    菜單跳轉(zhuǎn)時

    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 });}},

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

    總結(jié)

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

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。