vue部署到线上时,Loading chunk xxx failed 问题

此问题时常会出现在安卓各个机型,还会不定时出现这个问题,但在苹果各PC端都不会出现此问题

错误出现原因:安卓中部分内置浏览器对资源文件的加载优化不够,导致资源文件懒加载失败

解决方案:

1.看webpack配置是否正确

PublicPath配置为(vuecli3):publicPath: process.env.NODE_ENV === 'production' ? './' : '/',

即:publicPath:'./'

2.改变路由加载方式(取消懒加载):

import Vue from 'vue';
import Router from 'vue-router';
import store from '../store/vuex.js';

import Home from '../view/signwork/index' // 首页

Vue.use(Router);

const routes = [
  {
    path: '/',
    name: 'signindex',
    component: Home,
    meta: {title: "签到/签退"}
  },
  {
    path: '/signindex',
    name: 'signindex',
    component: Home,
    meta: {title: "签到/签退"}
  }
];

routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});
const router = new Router({
  routes,
 });
router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  //处理错误路径
  if (to.matched.length === 0) { 
    from.name ? next({
      name: from.name
    }) : next('/errorinfo'); 
  } else {
    next();
  }
  let checkload = setInterval(function(){             
    getconfig()
  }, 1 * 1800); 
  function getconfig(){
    if(store.state.isload){
       clearInterval(checkload)
    }else{
       window.location.reload()
    }
  }
});

export default router

 

注意的是先去import 资源文件,再去路由中调用,而不是边路由边调用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值