vue报错:Loading chunk * failed,vue-router懒加载出错问题。

目录

    • [一、 出现场景](#一、 出现场景)
    • [二、 解决方案](#二、 解决方案)

一、 出现场景

菜单路由跳转时,有时页面会卡死,无法进行路由跳转

二、 解决方案

修改src目录下permission.js文件

js 复制代码
router.onError((error) => {
  const jsPattern = /Loading chunk (\S)+ failed/g
  const cssPattern = /Loading CSS chunk (\S)+ failed/g
  const isChunkLoadFailed = error.message.match(jsPattern || cssPattern)
  const targetPath = router.history.pending.fullPath
  if (isChunkLoadFailed) {
    localStorage.setItem('targetPath', targetPath)
    window.location.reload()
  }
})

router.onReady(() => {
  const targetPath = localStorage.getItem('targetPath')
  const tryReload = localStorage.getItem('tryReload')
  if (targetPath) {
    localStorage.removeItem('targetPath')
    if (!tryReload) {
      router.replace(targetPath)
      localStorage.setItem('tryReload', true)
    } else {
      localStorage.removeItem('tryReload')
    }
  }
})
相关推荐
MyFreeIT1 天前
Page光标focus在某个控件
前端·javascript·vue.js
通往曙光的路上1 天前
day8_elementPlus
前端·javascript·vue.js
Simon_He1 天前
最强流式渲染,没有之一
前端·面试·ai编程
你真的可爱呀1 天前
uniapp学习【路由跳转 +数据请求+本地存储+常用组件】
前端·学习·uni-app
Jeffrey__Lin1 天前
解决ElementPlus使用ElMessageBox.confirm,出现层级低于el-table的问题
前端·javascript·elementui·vue·elementplus
Miketutu1 天前
vxe-table编辑模式适配el-date-picker
javascript·vue.js·elementui
咖啡の猫1 天前
Vue-MVVM 模型
前端·javascript·vue.js
xvmingjiang1 天前
Element Plus el-table 默认勾选行的方法
前端·javascript·vue.js
野生yumeko1 天前
伪静态WordPress/Vue
前端·javascript·vue.js
爱因斯坦乐1 天前
【vue】I18N国际化管理系统
前端·javascript·vue.js·笔记·前端框架